Helpful Tips

Here are some general notes on using variables:

  1. Variables are automatically "created" the first time a value is assigned to them.

  2. Variables are essentially typeless. You don't have to "declare" variables to be of a specific type, like in some programming languages. Instead, variables can hold any type of value. You can freely assign a string to a variable that currently contains a number, and vice-versa. (This doesn't mean that types aren't important...the type of the value itself still matters for actions and functions and such.)

  3. Variables are global by default. This means that once a variable is created, it is available throughout your project (unless you specifically make it a local variable).

Note: Variables persist throughout your update. This means that variables hold their values across events. If you assign a value to a variable on one event, it will still have that value on another event—and another—and another—until eventually you assign something else to that variable.

  1. Once a value has been assigned to a variable, it will continue to contain that value until you assign something else to it.

  2. Order is important.

    When creating and using variables, be sure to think about when and where they will be used, and what their values will be at that point in time. A variable that is only assigned a value at the end of the application won't have a value when your application starts up.

    For example, let's say you use a Dialog.Input action that asks the user for their name and stores it in a variable called UserName. It's important to realize that UserName won't contain the user's name until after that Dialog.Input action is performed. If the action is only performed after updating files, UserName won't have a value before the updating stage.

    The same is true for using variables within a script. When you assign a value to a variable, the value doesn't get assigned to the variable until that line of script is performed; in other words, it's value is only available to the actions that come "later." If you try to use the variable in an action higher "up" in the same script, or use it in another event that happens "earlier," the variable either won't have a value yet, or it won't have the value you expected it to have, and your update will either generate an error or not behave as you intended. (This is why it's important to test your update thoroughly before releasing it to the public.)

    A variable is only available to the parts of the your application that are performed after the variable is created. If you want to use a variable in an action later in the update, make sure a value is assigned to the variable before that action is performed.

  3. The built-in variables are listed along with all of the actions and constants when you press Ctrl+Space in the action editor.