Global code is not executed. In global space you declare functions, variables, and definitions. These can then be used in any script you want.
The below are examples of variable declarations. These variables can be accessed exactly like the variables you create the the script editor's [Variables] button.
- Code: Select all
int variable;
int array[10];
char string[256];
You can also declare functions in global code, which are executed when you call them. Functions can be used to make your coding cleaner, and reusable. So if you find yourself repeating code between events or actors, you should make it a global function, that way you only have to call one line of code.
- Code: Select all
// sets r g or b to 0 if it is 255
// otherwise set to 0
void
toggle_color ()
{
r=(r!=255)*255;
g=(g!=255)*255;
b=(b!=255)*255;
}
If for some reason you wanted to use the above code a lot, you can call it like this.
- Code: Select all
toggle_color();
Though the example wasn't all that practical, writing functions helps a lot. Even if you aren't writing the code a lot, it is helpful to have things written as functions as it makes searching for problems and fixing things up easier.