Home | Customize | Blog | Extras | Log In | Info
Manual | D&D icons | GML Parser | Archive | Iso City
Username: Password:  
About | Features | Directory | Banners | Contact

Designing Games with GameMaker
Designing Games with GameMaker

Extra variables

You create new variables by assigning a value to them (no need to declare them first). If you simply use a variable name, the variable will be stored with the current object instance only. So don't expect to find it when dealing with another object (or another instance of the same object) later. You can also set and read variables in other objects by putting the object name with a dot before the variable name.

To create global variables, that are visible to all object instances, precede them with the word global and a dot. So for example you can write:

{
  if (global.doit)
  {
    // do something
    global.doit = false;
  }
}

Alternatively you can declare the variables as being global. This declaration looks as follows.

globalvar <varname1>,<varname2>,<varname3>, ... ;

Once this declaration has been executed, the variable is always treated as global without the need to put the word global and a dot in front of it. It only needs to be declared once in a piece of code that is executed. After that in all other places the variable is considered as being global.

Sometimes you want variables only within the current piece of code or script. In this way you avoid wasting memory and you are sure there is no naming conflict. It is also faster than using global variables. To achieve this you must declare the variables at the beginning of the piece of code using the keyword var. This declaration looks as follows.

var <varname1>,<varname2>,<varname3>, ... ;

For example, you can write:

{
  var xx,yy;
  xx = x+10;
  yy = y+10;
  instance_create(xx,yy,ball);
}

Search Search


Alternative versions Alternative versions

You can also read this manual on one single long page (± 1.5 mb)

Also available in: Dutch French German

ZIP Download helpfile

Advertisement Advertisement

GameMaker Manual