Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Gamemaker Essentials

You're reading from   Gamemaker Essentials Learn all the essential skills of GameMaker: Studio and start making your own impressive games with ease

Arrow left icon
Product type Paperback
Published in Mar 2015
Publisher
ISBN-13 9781784396121
Length 154 pages
Edition 1st Edition
Arrow right icon
Toc

Statements and loops


In nearly every programming language, there is the option to use statements such as if and else. Often, we need to use loops such as the for loop. Statements and loops make a programmer's life much easier when it comes to keeping code readable and organized, so let's take a look at how these look in GML.

Loops allow developers to greatly reduce the amount of code needed to execute a repetitive task. Instead of using multiple if statements, the programmer can summarize it all into a single loop, keeping the code short and concise.

Statements

First, we will look at the simpler of the two statements. We will begin with the most commonly 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 programmer will often use brackets to enclose...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image