Assign Variable


This action is used to either assign a variable a value (creating it in the process) or for changing the value of an existing variable. You give the name of the variable and then the value, which can be added relative to the original value if required. If you give a new variable name (ie: a variable that has never been assigned previously in the instance) then this will create the new variable and assign it the value you give, while if you give the name of an existing variable, it will simply change the value to the new one. Note that checking Is Relative will add the value to the existing variable value (use a negative number to subtract) and you can also use expressions and variables created previously as the value.

It is worth noting that when we talk about "values", we don't just mean numeric values, as a variable can be a string, a pointer, a resource ID or anything else that a function can return or use. In the case of a string, checking Is Relative will concatenate the value with whatever the variable previously held, so if your variable was "Hello" and you assign " World" to it using the relative check, the final variable value will be "Hello World". Care must be taken, however, to ensure that the variable values are both of the same data type, as trying to add, for example, an integer and a string, will result in a compiler error.

Note that you can add additional variables in the same action by clicking the plus icon beside the action, and giving another variable name and value. For more advanced information on variables please see the section on Variables And Variable Scope.

Action Syntax:

Assign Variable Syntax


Argument Description
Name The name of the new variable to assign, or the name of an existing variable to change.
Value The value that the variable should hold.
Is Relative Check to set the value relative to the previous one.


Assign Variable Action Example

The above action block code checks two instance variables and if one is higher than another ( if "my_score" is greater than "level_score"), then it sets a number of instance variables to new values.