Thursday, April 4, 2013

Intro to GML Part 1: Variables

Here's part 1 of a multiple (as yet undetermined) part series on GML (Game Maker Language).  I've seen a few posts of people having virtually no idea about using GML, and hopefully this series will solve that.

What Are Variables?


A variable  is used to store information in GML.  They can store a lot of things, ranging from numbers to strings.  You can then manipulate them to achieve a number of purposes.

So, how do you use variables in GML?


Well, you have to declare them and identify them.  Usually this is done in one step, like this:

aNumber = 1;

This sets a variable named aNumber equal to 1.  You can then use this variable to perform different operations.  Let's say you wanted to add 1 to aNumber:

return aNumber + 1;

You'd get 2 as the return value.

Built-In Variables


GML has a bunch of built-in variables that you can use.  You don't even need to declare them.  Here's a short rundown of a few common built-in variables:

x
The horizontal position of something in the coordinate system
y
The vertical position of something in the coordinate system
hspeed
The pixels per step and object is moving horizontally
vspeed
The pixels per step and object is moving vertically

You use these variables to move objects around, and find out where things are in your game.  Of course, GML has many more built in variables than this, but it's best to take things in small bits at a time.

Ok, hopefully this gives you some idea about how variables work in GML, I'd be happy to anwer any questions in the comments.

No comments:

Post a Comment