Before we get started, you should know how to use the code object. This is simple, just go to control and add "Execute code." This will be the only object you will need to use.
Variables are named values. Game maker uses variables kind of like how you would share 4 cookies with a friend. There are 4 cookies, that's a variable, but in game maker it looks a little different.
Instead of saying There are 4 cookies, we use; Cookies = 4;. Cookies is the variable and 4 is the value of the variable. It is pretty easy to understand, but it gets a little more complicated. There are two types of variables we can use in game maker. Global and Local.
Local: A local variable only stays with the object. You declare it like this: Variable = # or "String"
Global: A global variable goes through every room, every part, and everything. It is declared like this: global.variable = # or "string" ____
Numbers: variable = 0 String: variable = "betrayalgaming.weebly.com" function: Variable = get_string("What is your name", "Name here") ______________________________________________________________________________________________ I have included an example for those who need a better explanation on the difference between global and local.
You may have noticed a few codes that were not explained in the example, so I will give you a few bonus codes!
get_string("Question","Starting Text in the box"): This allows users to define the text in a variable or object. draw_text( x, y, "text" or variable): Draws text or a variable on the x and y coordinates room_goto(room here): moves to the defined room
Now that you understand how to define variables, I will tell you a bit on editing variables before we move on.
Adding to a variable: += Subtracting from a variable: -= multiplication and division work the same way: *= and /= set to a certain number: variable = #