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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

store either a real number or a string. Variables do not need to be declared like in many other<br />

languages. There are a large number of built-in variables. Some are general, like mouse_x<br />

and mouse_y that indicate the current mouse position, while all others are local to the object<br />

instance for which we execute the program, like x and y that indicate the current position of<br />

the instance. A variable has a name that must start <strong>with</strong> a letter and can contain only letters,<br />

numbers, and the underscore symbol '_'. (The maximal length is 64 symbols.) When you use a<br />

new variable it is local to the current instance and is not known in programs for other<br />

instances (even of the same object). You can though refer to variables in other instances; see<br />

below.<br />

Assignments<br />

An assignment stores a value in a variable. An assignment has the form:<br />

= ;<br />

An expression can be a simple value but can also be more complicated. Rather than assigning<br />

a value to a variable, one can also add the value to the current value of the variable using +=.<br />

Similar, you can subtract it using -=, multiply it using *=, divide it using /= ,or use bitwise<br />

operators using |=, &\, or ^=.<br />

Expressions<br />

Expressions can be real numbers (e.g. 3.4), hexadecimal numbers, starting <strong>with</strong> a $ sign (e.g.<br />

$00FFAA), strings between single or double quotes (e.g. 'hello' or “hello”) or more complicated<br />

expressions. For expressions, the following binary operators exist (in order of priority):<br />

• && || ^^: combine Boolean values (&& = and, || = or, ^^ = xor)<br />

• < >=: comparisons, result in true (1) or false (0)<br />

• | & ^: bitwise operators (| = bitwise or, & = bitwise and, ^ = bitwise xor)<br />

• >: bitwise operators ( > = shift right)<br />

• + -: addition, subtraction<br />

• * / div mod: multiplication, division, integer division, and modulo<br />

Note that value of x div y is the value of x/y rounded in the direction of zero to the nearest<br />

integer. The mod operator returns the remainder obtained by dividing its operands. In other<br />

words, x mod y = x - (x div y) * y. Also, the following unary operators exist:

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

Saved successfully!

Ooh no, something went wrong!