Game Development Reference
In-Depth Information
Statements
First, we will look at the simpler of the two statements. We will begin with the most com-
monly used statement, the if statement.
The if statement
The if statement allows us to ask our game questions and then tell it what to do depending
on the answer. The answer will either be true or false, never anything else.
In GameMaker, an if statement can be structured in multiple ways. An experienced pro-
grammer will often use brackets to enclose the functions or math used within an if state-
ment; however, in GML, this is not needed. It is still recommended though if you plan to
use other languages as it will help in learning languages structured the same way.
GameMaker updates may also begin imposing these formatting rules.
Let's look at an actual if statement in GameMaker.
In the preceding screenshot, the code is checking to see whether one is greater than than
two. Of course one is not greater than two, so this statement would return false as its result.
Based on the true or false result of an if statement, we then decide what to do. For ex-
ample, we may destroy an object if its health is lower than a certain value. Code executed
in accordance with an if statement should be enclosed in curly braces.
In the following screenshot, you can see the same statement but with a place for code to be
executed:
Search WWH ::




Custom Search