Game Maker

Test Variable

194pages on
this wiki
Test variable window

The Test Variable action can be used to check if a variable has a certain value, or a value greater or lower than that value.


variable is the name of the variable you want to check. value is the number or string that you want to check for. operation is how you want to check for that value.

equal to means Test Variable will return true only if the value of the variable is precisely the same as the one tested for.
smaller than will return true even if the value tested for is smaller than the value of the variable.
larger than will return true even if the value tested for is larger than the value of the variable.

NOT will reverse the conclusion of the test


Example 1Edit

You want to move to another level when the player has reached a score larger than 500. Before changing the level, do a Test Variable with:

variable: score

value: 500

operation: larger than

leave NOT unchecked.

Now the level would only change if the score is large enough.

Example 2Edit

In a platformer game, you would not want the player to be able to jump unless they are standing on the ground. So before you set the speed that makes them jump, you do a Test Variable with these parameters:

variable: place_meeting(x,y+1,obj_floor)

value: true

operation: equal to

leave NOT unchecked.

The code place_meeting(x,y+1,obj_floor) is used to check for whether a collision with obj_floor would occur one pixel below the player. This effectively checks for whether the player is on the ground.

See alsoEdit

Advertisement | Your ad here

Around Wikia's network

Random Wiki