variable_global_set

Set a given global variable to a value

Syntax:

variable_global_set(name, val);


Argument Description
name The name of the global variable to set (as a string)
val The value to set the global variable to


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


Description

With this function you can set the value of a given global variable. You supply the name of the global variable to set the value of as a string (see example code below), and then the value to set (can be any valid data type). If the global variable does not exist already in the game it will be created and then assigned the value.


Example:

if !variable_global_exists(id, "enemy_num")
   {
   variable_global_set("enemy_num", 0);
   }

The above code will check to see if a global variable exists and if it does not then it is created and set to 0.


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