Iron Realms Entertainment
Variables store data. They are simply there to contain any data that needs to be used in the program. They can have what is called ‘scope’ in that they may only be visible during certain portions of a routine or perhaps the entire project. They can be declared in a couple different ways.
Each variable has a specified scope when it is declared. The scope affects where in the source code it is visible and where it can be read or written to. For every scope except for “Project” scope, space is actually allocated for the variable when declared.
You can see several methods of declaration in the table above, however a few things need to be explained. First, to use a variable, it must be declared. In declaring a variable, you tell Rapture to allocate space in memory for the data that the variable will hold and also to give that space a name. All variables in Rapture are initialized to default values at different times depending on the scope of the variable. Global variables are initialized at load (and re-load) time, and locals upon entering the block they were declared in. To declare variables, you simply use the global or local keywords followed immediately by a comma separated list of variable names.
(* Declare some external variables (typically included in header files) *)
The above example also contains a subroutine definition, but it is present only to show how (and where) local variables are declared.