Functions |
Previous Next |
Working With Functions▪A script/macro in MADRIX Script consists of a set of functions. ▪Some of these functions are required and called by MADRIX. ▪Others may be used to split the script into smaller parts. ▪Functions form small parts of a script and hold a number of statements. ▪They can be called from other parts of the script in order to execute their statements. ▪Having statements used outside of functions is not allowed in MADRIX Script.
Creating FunctionsFunctions consist of a head and a body. The head describes the name of the function, its parameters, and its return value. Whereas, the body includes a block of statements, like this one: void function(int p)
The first data type, stated in front of the function, describes the kind of value the function returns and it may be of any known data type. In the case above, no value is returned by the function and therefore void is declared. The actual name of the function can be any name that follows the rules of identifiers in MADRIX Script as was discussed above. But it has to be unique. It is not allowed to have several functions with the same name or with the name of global variables or constants. The parameter list following the name of the function may be left empty, but it is necessary to keep the brackets (). Different parameters are separated by comma. A parameter can take on any data type possible. Here are three examples for function declarations: void setPixel(int point[])
Passing Parameters In MADRIX ScriptParameters are always passed via copy by value (The exception are »arrays). This means that a parameter may be used as another local variable of a function. Changing the value of a variable does not change the variable the caller has provided. void testFunc(int i, int ia[]) In testFunc the parameter i is set to 5 and the array that is passed is filled with several values. After the return of the function in RenderEffect, the array is now filled with the values set in testFunc. Whereas the variable len has not changed and still has a value of 2. Note: Passed parameters are always copied to a function, while this is not the case with arrays.
Returning A ValueTo return a value, the return statement must be used followed by an expression. The given expression must result in the same or at least a compatible data type of the declared function's type. It must be the last statement of any function which returns a value unequal to void. In addition, return can be used to leave a function early. For void functions return will be used without an expression. Here are some examples: int[] CreatePoint(int x, int y) Functions Called By MADRIX▪Each macro or script includes a number of predefined functions called by MADRIX. ▪If a function is not needed by a script, it is not necessary to implement it. A message is printed out if one of them is missing. This is not an error, but only an information for the developer of the script. ▪Please note that each component of the MADRIX Script language (MAS Script Effect, Effect Macros, Storage Place Macro, Global Macro) may include a different combination of these five functions as this is just an overview:
void InitEffect() ▪More information is available in the corresponding chapters.
Further Information▪There are a lot of functions which can be used in MADRIX Script for different functionality (e.g., to draw objects the matrix, get the data of the sound analysis, or mathematical functions). ▪Learn more »List Of Functions (Alphabetical Order)
|
MADRIX Version: 5.7 | Script Version: 3.23 |
[Ctrl & +/-] = Zoom In/Out | [Ctrl & 0] = 100% |
Previous
Next
|
Enable automatic translation | Activer la traduction automatique | |