08.11.2012 Views

Designing Games with Game Maker - YoYo Games

Designing Games with Game Maker - YoYo Games

Designing Games with Game Maker - YoYo Games

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

To create global variables, that are visible to all object instances, precede them <strong>with</strong> the word<br />

global and a dot. So for example you can write:<br />

{<br />

}<br />

if (global.doit)<br />

{<br />

}<br />

// do something<br />

global.doit = false;<br />

Alternatively you can declare the variables as being global. This declaration looks as follows.<br />

globalvar ,,, ... ;<br />

Once this declaration has been executed, the variable is always treated as global <strong>with</strong>out the<br />

need to put the word global and a dot in front of it. It only needs to be declared once in a<br />

piece of code that is executed. After that in all other places the variable is considered as being<br />

global.<br />

Sometimes you want variables only <strong>with</strong>in the current piece of code or script. In this way you<br />

avoid wasting memory and you are sure there is no naming conflict. It is also faster than using<br />

global variables. To achieve this you must declare the variables at the beginning of the piece<br />

of code using the keyword var. This declaration looks as follows.<br />

var ,,, ... ;<br />

For example, you can write:<br />

{<br />

var xx,yy;<br />

xx = x+10;<br />

yy = y+10;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!