With this function you can get the value from a given named variable. You supply the unique instance ID value (which can be found from the Instance Properties in the room editor, or is returned when you call the function instance_create_layer) as well as the name of the variable to get the value of as a string (see example code below). The function will return the value held by the variable.

NOTE: This function is primarily for use with Compatibility Scripts for imported projects and the converted code for Drag and Drop actions.

IMPORTANT! If the variable you are getting does not exist then the function will return the keyword undefined and you may get errors that will stop the game from functioning, so if in doubt use the function variable_instance_exists first.


variable_instance_get(instance_id, name);

Argument Description
instance_id The unique ID value of the instance to use
name The name of the variable to get (as a string)


Value (any data type) or undefined (if the named variable does not exist)


if variable_instance_exists(id, "shields")
   var ss = variable_instance_get(id, "shields");
   var ss = -1;

The above code will check to see if a variable exists and if it does then the value it holds is retrieved and stored in a local variable. If it does not exist, the local variable is set to -1.