GS2 is different from many other programming languages, Graal Scripts variables are 'variant' and are objects that hold values of different types. When the value is assigned the variable assigns it to the right type.
Numeric (floating point / decimal)
String (text)
Object link
Array (list of objects)
var[0] = 1;
var[1] = "stuff";
var[2] = player;
Also, using the type() function "variable.type()" returns 0,1,2,3 for numeric, string, object, or array. This will give -1 for constants.
You can also put arrays into arrays.
var[0][3] = 4;
var[1][1] = 7;
var[2] = 11,12,13,14,15;
There are also built in variables here:
http://www.graal.net/index.php/Creation/Dev/Script/Client
Constants are defined by the keyword 'const'
Because temp.val is not constant it will not work.
However, to use const intVar, you don't need the const in front of it any longer. Also, player.variables cannot be defined as a constant, nor can client(r).variables.
Constants can be used to keep a variable from changing due to foreign script interference. They can also be used to give cryptic values an easy to understand name by putting a const at the beginning of the script.
Enumerators are another 'special' type of constants.
test1 = 0;
test2 = 1;
test5 = 2;
testStuff.test1 = 0;
testStuff.test2 = 1;
testStuff.test5 = 2;
enum0 = 10;
enum1 = 11;
enum2 = "string";
enum4 = 12;
http://www.graal.net/index.php/Creation/Dev/GScript/Constants
http://www.graal.net/index.php/Creation/Dev/Script/Starting_Guide#Standard_functions
Numeric (floating point / decimal)
- Code:
var = 1;
String (text)
- Code:
var = "stuff";
Object link
- Code:
var = player;
Array (list of objects)
- Code:
var = {1,"stuff",player};
var[0] = 1;
var[1] = "stuff";
var[2] = player;
Also, using the type() function "variable.type()" returns 0,1,2,3 for numeric, string, object, or array. This will give -1 for constants.
You can also put arrays into arrays.
- Code:
var = {
{1, 2, 3, 4, 5},
{6, 7, 8, 9, 10},
{11,12,13,14,15}
};
var[0][3] = 4;
var[1][1] = 7;
var[2] = 11,12,13,14,15;
There are also built in variables here:
http://www.graal.net/index.php/Creation/Dev/Script/Client
Constants are defined by the keyword 'const'
- Code:
const intVar = temp.val; //Bad
const intVar = 22; //Good
Because temp.val is not constant it will not work.
- Code:
intVar = 21; //Bad
player.chat = intVar; //Good
However, to use const intVar, you don't need the const in front of it any longer. Also, player.variables cannot be defined as a constant, nor can client(r).variables.
Constants can be used to keep a variable from changing due to foreign script interference. They can also be used to give cryptic values an easy to understand name by putting a const at the beginning of the script.
Enumerators are another 'special' type of constants.
- Code:
enum {
test1,
test2,
test5
};
test1 = 0;
test2 = 1;
test5 = 2;
- Code:
enum testStuff {
test1,
test2,
test5
};
testStuff.test1 = 0;
testStuff.test2 = 1;
testStuff.test5 = 2;
- Code:
enum {
enum0 = 10,
enum1,
enum2 = "string",
enum4
};
enum0 = 10;
enum1 = 11;
enum2 = "string";
enum4 = 12;
http://www.graal.net/index.php/Creation/Dev/GScript/Constants
http://www.graal.net/index.php/Creation/Dev/Script/Starting_Guide#Standard_functions