Variables hold data while a player is playing a game.
There are two types of variables. Local and Global.
The name of a variable can only contain numbers, letters, or underscores.
Variables are constructed like this:
name of variable=value;
A local variable is a variable that is only used in one object.
If you put the variable code in the Create Event of an object, then that variable can only be used in that object.
This local variable tells how much food the player has left.
A global variable can be used in any object in the game.
The only difference is that you add global before the variable name.
Changing the Value of a Variable
This code subtracts 1 from the variable global.player_hp. Notice the -=.
This code adds 10 to the same variable. Notice how the -= is now +=.
This code draws the health variable on the screen:
draw_text(125,75,"Health: " + string(global.player_hp));
Here is the breakdown of the code:
draw_text(x-position,y-position,"text text text" + string(the variable you want to draw));
The x-position and y-position is where you want the text to be drawn.
The "text text text" can be changed to "Health:", "Money:" or anything else you want it to be.
The "+ string(variable)" is adding the variable (which is a string) to the rest of the text.