If Variable Icon If Variable

This action is used to check the state of a given variable against a given value using a specific expression. An "if" statement will always return either true or false and the expressions for checking can be any one of the following:

If you flag the "Not" argument, then the above will be negated expressions, for example "equals to" becomes "not equals to". Also note that neither the variable nor the value arguments are limited to numeric values and can be a string, a pointer, a resource ID or anything else that a function can return or use (see the section on Data Types for more information), but you cannot compare two different data types without getting an error - for example if the variable holds a string and you try to check if it is equal to a number then you will get a syntax error.

IMPORTANT Due to floating point precision issues, checking to see if two values are exactly equal may return false, since one may be exactly 1, while the other may be 1.00000000000001. This can be avoided by using the Decimal To Integer action before checking or using the "greater than" or "less than" expressions.

Note that to add actions into the "if" block, they should be dropped to the side of the action, as shown in the image below:

If Variable drop actions exampleThese actions will now be run if the "if" evaluates to true, while any actions dropped elsewhere will be performed after the "if" block.

 

Action Syntax:

If Variable Action

Arguments:

ArgumentDescription
VariableThe name of the variable to check.
NotSet to check if the expression does not evaluate to true.
ExpressionThe type of expression to use for the check.
ValueThe value to check the variable against.

 

Example:

If Variable ExampleThe above action block code checks a variable "dir" to see if it is equal to 10, and if it is it creates an instance of "obj_Squirrel" and if it isn't then it destroys the instance.