Part 1 - variable definitions
Let's start
First off, let's get you to know what is Global Code.
you can find the Global Code from GE's main menu -> Script -> Global Code.
Or from any script event from script editor windows bottom:
Global code as GE's documentation explains it:
Documentation http://game-editor.com/docs/scripting.htm wrote:Use the Global Code Editor to freely add any 'C' code (arrays, structs, and functions). The sky is the limit when you use this Editor but you should have your feet well grounded in the C Programming Language in order to use the Global Editor effectively. Your knowledge of the 'C' language will serve you well here.
Global Code can be accessed by any script.
Global code is something where you can code your own functions freely.
It is very good to learn using Global Code - it will save you a lot time if you get used
to using it!
Defining variables
You can define global variables and actor variables by clicking "variables" at the bottom of the window:
Or
You can use Global Code to create global variables.
For creating an integer variable, write this:
- Code: Select all
int myVar;
myVar is the name of the variable.
For creating a floating point variable, write:
- Code: Select all
double myVar;
or
- Code: Select all
float myVar;
For creating a string, write:
- Code: Select all
char myString[255];
You can replace 255 with any number that is littler than 255. 255 is GE's limit.
So now you see that this [255] is affecting the size of the string, which actually is an array of chars.
Arrays
All other variable types can also have arrays, like this:
- Code: Select all
int myVar[5];
That would create 5 variables,
myVar[0],
myVar[1],
myVar[2],
myVar[3],
and myVar[4].
You always have to remember that the arrays start with [0] and the highest usable array number is one less than what you've used when creating the array. So, if I had defined that array above and tried to use this code:
- Code: Select all
myVar[5] = 10;
I'd get an error message, because there is no myVar[5]. Hope you understood this.
Multidimensional arrays
You can also define multidimensional arrays.
- Code: Select all
int myArray[5][5];
That would create 5 * 5 integers, which means 25 integers!
To use them, do it like this:
- Code: Select all
myArray[1][2] = 10;
So the first number means the level of array from which to get the 2nd integer.
This pic explains it quite well:
Also strings can have multiple dimensions, just write like this:
- Code: Select all
char myStringArray[5][255];
And your variables can have even more dimensions, just add more "[]".
Giving variable a start value
You can give start values to variables. For integer, double or float do it this way:
- Code: Select all
int myInteger = 5;
double myDouble = 5.5;
float myFloat = 5.25;
So just add "=" and what you want it to be. Then put the semicolon.
When you want to give string a start value, do it this way:
- Code: Select all
char myString[255] = "Hello everybody";
That was about defining variables Let's get to function writing next!