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