Game Maker Language Notes
Notes that are about GameMaker Studios coding Language.
GML
Game Maker Language, used by GameMaker Studio
Variable
A storage location in the computer memory, paired with a name, that contains data
A named piece of data
A box that holds something with a label on it
A way to store data (to access or change it later)
How to name a variable
Requirements
Letters(case sensitive), numbers, and underscores
Star with a letter or underscore
Conventions
Clear and descriptive names
Readability and consistency
Using a Variable
Set(initialize) before use
ex. player_name = "Korae"
player_health = 100
Changing is the same as setting
ex. player_name = "Loser"
player_health = player_health - 1
Reference
ex. if(player_health <= 25){
draw_text(x, y, "you're low on health!")
}
You can't reference a variable without setting it
Varialbe Scope
The place where you can validly reference a variable by name
Allows variables to have the same name
Three Scope Categories
Global
Can be accessed by everything
Has a special declaration
ex. global.volume = 100
Remains in memory until the game ends
Only use when you need to use the same information across multiple objects and only one type of that information is needed
Instance
Created within an instance of an object
Unique to that instance
Most common, no special declaration
Unique to that instance
Destroyed when instance is destroyed
Local
Created for a specific event or script
Have a special declaration
ex. var_value = 5
Discarded when the event has finished
Good for when information needs to be created or held onto for a specific event
Data Types
When you create a variable it can be used to hold information, and when you call a function, it can also store returned information. However, this information can come in various "flavours" - for example, it can be a real number or it can be a string. These different types of values being used are called data types.
An attribute of the data that tells the computer how to treat it
Defines the operations that can be done
Ex. 5*5 vs John*John
Common Data Types
Strings (text)
Text
Must use quotation marks
ex. string = "Hello"
Built in string functionality
Real Numbers
Any real number
ex. number = 5
Default data type
Built in number functionality
Booleans (true false)
A value that can be either true or false
ex. bool = true
Arrays (special)
Data that holds other types of data
Like a list
The variable is not the data, but a reference to the data
Built in array functionality
All GML Data Types
Real Numbers
Boolean
Strings
Arrays
Structs
Method Variables
A variable that has been assigned a function
must use name = function(){} format
ex. a_method = function(){//stuff}
int64
Handles
Hexadecimal Literals
Binary Literals
Pointer
Enum
Undefined
NaN
Infinity
Any