Variables are used in almost every script of code that you will ever write. Why because variables store information!
You can type:
hello = 2
And now hello is storing the number to 2, or in other words hello now has the value of 2. Variables are not very limited. You can store text as well! Normally when writing code it's called a string.
hello = string('Hello world!')Now the variable hello is storing the string "Hello World!"
You can use this variable to say this to the user like this:
hello = string('Hello world!')
When you run this code, a box will pop up and say: Hello world! Why? Because you are using a function called show message, this function shows a message to the user in a pop up box, and when you told it to display the information held by the variable hello it did and the information of hello is the words "Hello world!". You do not have to use variables. You can just say:
You might have noticed that this time inside the () I placed '' that is because that means that what ever I place inside those is a string. Before I wanted to use a variable that held a string, not a direct string. Going back to variables you can add them multiply them and divide them.
var hello, hi, greetings;
hello = 3 +4
hi = 5 * 6
greetings = hi - hello
If you run this code then you will see the number 23.
That is because the script was run from top to bottom (as always) and it first established that there were 3 variables hello hi and greetings, then it realized that hello = 3+4 it added it up and knew that hello = 7, then it saw that hi = 5*6, a definite 30, then it saw that greetings = hi - hello, knowing that hi = 30 and hello = 7 it arrived at the conclusion of a total 23. Then it was told to tell the user in a pop up box what it had just found out: what does greetings =?
So you see, it's very simple. You just got the computer all exited and let him tell you what he found out. No. Actually you just made a program that calculates variables and displays the answer to the user.
Do you feel smart?
You should! Because you know now how to program with GML!
Want to know more?
This post was a good start but,
for a really good gml reference got to: