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

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};
}

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