• Home
  • Tutorials
  • Downloads
  • Games
  • Articles
  • Contact

Statements

There are a variety of statements for you to use within your programs. However, we are only going to cover the important conditional statement, the if statement.


This statement has several forms:
Picture

These 3 variations all have their uses.

The general idea of this conditional statement is to evaluate a statement and decide whether it is true or false. If it evaluates to true, the defined actions take place. If it evaluates to false, optionally defined actions take place.

The {} brackets are used if you want to define multiple actions. It is common practice to indent any code written within {} brackets.

Expressions
In order to decide whether a statement evaluates to true or false, expressions are used. Common expressions include:

  • Addition: +
  • Subtraction: -
  • Division: /
  • Multiplication: *
  • Less than and greater than: < >
  • Comparison: ==
  • Not: !

Furthermore:

  • And: &&
  • Or: ||

These 2 terms can be used in their written forms of "and" - "or" too, which we will do for your understanding.
Examples
Let's look at the variations of the if statement and their uses.

This statement in itself can be very useful. For example, say we wanted to display a message when an instance of an object has its health_points variable equal to 0. The following use of a conditional statement means the message will only be shown when the variable equals the defined value:
Picture

This syntax can be extended further:
Picture
In this case, the term else defines what happens if health_points does not equal 0.

If we wanted to execute multiple actions, or define evaluate multiple statements, we need to use {} brackets:
Picture

The if statement is a very powerful tool, and in time you'll be able to fully appreciate its use. By making use of this statement, you will now be able to code a vast variety of new functionality.

Finished!
And that's it, you know basic GML! It's recommended you play around with your new skills and try to code some basic games. Refer to the help file frequently, and avoid the draw event for now.

You can start learning about the theoretical side of networking with our tutorial now, in preparation to starting work on your MMORPG. Your skills will only improve from here!
Picture
Picture

How To Make An MMORPG © 2010-2012
Copyright | Privacy Policy