Units are groupings of functions and also variables.
They can be thought of as modules or namespaces. A Mezzanine script must have at least one unit.Unit must be followed with a unique unit name. Units are defined as follows.
unit MyUnit;
// Other code follows
string myVar;
int factorial(int x){
if(x ==0|| x ==1){
return1;
}elseif(x >1){
return factorial(x -1);
}
return0;
}
HEADS UPObjects, enums and validators are global, so they can optionally be in a separate source code file without a unit.
Mez File Comments
Two types of comments are supported
Single line comments
// date tstamp = System.now();
// decimal rand = System.random();
And multi-line comments:
/* date tstamp = System.now();
decimal rand = System.random(); */
This unit has one unit variable named myVar. This variable has unit scope and can be accessed by any function in the unit. The unit also has a function named factorial. A unit must have at least one function. To refer to a unit’s member functions or variables from another unit, you have to use the scope operator
unit TestUnit;
void test(){
MyUnit:myVar ="New string value!";
int f =MyUnit:factorial(5);
}
Note: Unit variables cannot be in line initialized when they are declared. The following code will not compile
unit MyUnit;
string myVar ="some value";// this is not a legal statement
No labels
0 Comments
You are not logged in. Any changes you make will be marked as anonymous. You may want to Log In if you already have an account.
0 Comments