If statement

Game Maker 8

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