variable_instance_set

Set the value of a given instance variable

Syntax:

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


Returns: N/A


Description

With this function you can set the value of a given named variable. You supply the unique instance ID value (which can be found from the room editor, or is returned when you call the function instance_create) as well as the name of the variable to get the value of as a string (see example code below). If the variable does not exist already in the instance it will be created and then assigned the value.


Example:

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.


Back: Variables And Variable Scope
Next: variable_global_exists
© Copyright YoYo Games Ltd. 2018 All Rights Reserved