GS Syntax

From HIVE
Revision as of 12:24, 1 November 2010 by DevliN (talk | contribs) (Added SC2 category)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Loops

for loop

The for loop is generally used to count through an amount of numbers, and at each interval, do something.


//Example
for ( x = 0; x < 10; x++ ) { //Basic for loop
   lv_randomVariable = 9 //Here you place the action that you are going to do.
} //And of course, the end curly bracket to close off the loop.


Now let's discuss what the example is doing. The first line after the comment ("//Example") basically means "set x to 0, and as long as x is less than 10, add 1 to x. The second line is what actually happens as long as x is less than 10; in this case, it sets randomVariable to 9. The third line simply ends the for loop.

Variables

Variables are simply objects that can be set to a value, e.g. randomVariable can be set to 3 or false or hello, etc.

Variables in GS can be local or global. Local variables are used just in one trigger (or function, depending on how you look at it). Global variables can be used throughout the entire script.

To define a global variables, use

//Global Variables
int gv_randomVariable;

And to set that variable, use

void InitGlobals () {
    gv_randomVariable = 0;
}

Local variables are defined inside the trigger/function that they're used in.

// Trigger: blah
bool gt_blah_Func (bool testConds, bool runActions) {
   // Variable Declarations
   int lv_randomLocalVariable;
   // Variable Initialization
   lv_randomLocalVariable = 0;
   return true;
}