Add/Edit Event Variable dialog

The Add/Edit Event Variable dialog allows you to set the name, type and initial value of a global or local variable in an event sheet.

The Add/Edit Event Variable dialog

The Name identifies the event variable. This is typed in to expressions to retrieve the value of the event variable. Some names cannot be used, like the names of system expressions, since they would conflict when entering an expression.

The Type specifies what kind of value the variable holds. An event variable can store either a Number or Text (also known as a string). The type of an event variable does not change - you can't store text in a Number variable and vice versa.

The Initial value is the initial number for a Number variable, else the initial text for a Text variable. Initial text can be empty. The initial text entered here does not need double quotes around it. In other words, Hello is a valid entry, and if you enter "Hello" the initial string will include the double quotes. Note this is different to entering strings in expressions which require the double quotes.

The Description is an optional comment you can use to briefly describe what the variable is used for. It is displayed next to the name in the editor to help remind you what to use the variable for.

The Static checkbox only applies to local variables. By default, local variables reset their value to the initial value every tick. However, if Static is checked, the local variable's value will persist permanently, like a global variable. Static local variables differ from global variables in that they can still only be used within their scope. Global variables always hold their values permanently so the Static option does not apply to them. For more information about local variables, see Event Variables.

The Constant checkbox makes a variable read-only. You will be able to compare and retrieve the variable, but not change its value using any actions. This is useful for referring to a number like the maximum number of lives, without having to repeat the number in your events. If you want to change the value, there is only one place you need to change, which is a lot easier than having to hunt down the multiple places you entered a particular number in your events. According to programming convention, the names of constants are displayed in upper case, e.g. MAX_LIVES.

Tags: