With this function you can set the value of a given variable in an instance. 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 set the value of as a string (see example code below), and then finally the value to set (can be any valid data type). If the variable does not exist already in the instance it will be created and then assigned the value.NOTE: This function is primarily for use with Compatibility Scripts for imported projects and the converted code for Drag and Drop actions.
variable_instance_set(instance_id, name, val);
Argument Description instance_id The unique ID value of the instance to use name The name of the variable to set (as a string) val The value to set the variable to
if !variable_instance_exists(id, "shields")
variable_instance_set(id, "shields", 0);
The above code will check to see if an instance variable exists in the calling instance and if it does not then it is created and set to 0.