'If' And 'Else If' Statements |
Previous Next |
'If' ConstructVery often it is necessary to make decisions within a script/macro. You could for example want to use red as your background color every day if it is after 9 a.m. Or for example, it could be your wish to clear the matrix and change the color if the matrix has been filled up completely. Therefore, in MADRIX Script the keywords if and else exist. They may be used like this:if(condition) The first statement is executed if the given condition is true or unequal to 0. Otherwise the second statement, stated after else, is executed. Statement may include a single statement or a block of statements and the else-part is optional. Here are some examples for the if-statement: if(x % 2 == 0) It is important to consider that an else always refers to the last if-statement. However, blocks may be used to make the intention clear. To give you a demonstration, please consider the following example. It may be interpreted wrong since i will be incremented if the j > i-condition fails and not if the i > 3-condition fails, as is implied by the given else. if(i > 3) To let the compiler create the correct code, use blocks: if(i > 3) 'Else If' ConstructElse if is an additional structure to implement decisions. It may be used like this: if(condition) Like described above, else is always followed by a statement. And if is such a statement. Then, it is logical that an else can be directly followed by an if. The else if structure is very useful to make code with a lot of decisions more readable. It enables you to check for different conditions, which shall only be checked if the previous condition was passed successfully. Here is an example which selects another color for different days. Simply copy and paste it in the function RenderEffect. date t = GetDate(); Full ExampleThe following example for the MAS Script Effect renders a blinking cross onto the matrix. Instead of using random colors, predefined colors will be used. During each call of RenderEffect, the color will be chosen. color colCross = {0, 255, 255, 255}; |
MADRIX Version: 5.7 | Script Version: 3.23 |
[Ctrl & +/-] = Zoom In/Out | [Ctrl & 0] = 100% |
Previous
Next
|
Enable automatic translation | Activer la traduction automatique | |