Designing Games with GameMaker
If statement
An if statement has the form
if (<expression>) <statement>
or
if (<expression>) <statement> else <statement>
The statement can also be a block. The expression will be evaluated. If the (rounded) value is <=0 (false) the statement after else is executed, otherwise (true) the other statement is executed. It is a good habit to always put curly brackets around the statements in the if statement. So best use
if (<expression>) { <statement> } else { <statement> }
Example
The following program moves the object toward the middle of the screen.
{ if (x<200) {x += 4} else {x -= 4}; }
« Arrays | Repeat statement »
Alternative versions
You can also read this manual on one single long page (± 1.5 mb)
Also available in:
Download helpfile
Also available in:
Download helpfile