Variables

General

A variable is a named value which changes over time e.g. the level of the battery, the time of day.

When Tasker encounters a variable name in a text, it replaces the name with the current value of the relevant variable before carrying out the action.

The main purposes of variables are:

Built-In Variables

The values of Built-In variables are updated by Tasker. Their names always use all-capital letters.
General Notes

Variables marked dynamic in the list above trigger changes in Variable Value states and Variable Set events whenever their value changes.

Variables marked monitored will cause the relevant monitor to startup to track their state when they are used in contexts or tasks which are used by widgets or enabled profiles. For instance, %CELLS used in a Flash action will cause cell location to be tracked.

Limitation: monitored variables cannot be detected in anonymous shortcuts.

Note On Location Variables

When the relevant provider (Net or GPS) of a location context is active, these variables report the values from the provider, which may be more recent than Tasker has seen if other applications are asking for location.

When the relevant provider is not active, these variables report the last values seen by Tasker, which could be the result of a Get Location action or of monitoring for a Location Context.

That means the the reported fix times could go backwards, if you turn off the location provider between two uses of the variables.

Location variables can also be manually updated by running the Get Location action.

User Variables

The action Variable Set (and several others) can be used to create new variables. Variable names have the following restrictions:
Global vs Local Variables
All built-in variables are global, meaning they are visible anywhere in Tasker (e.g. %WIFI)

User variables which have one or more capital letters in their name are also global (e.g. %Car)

However, user variables which have all-lower-case names (e.g. %fruit) are local, meaning they are only visible in the task in which they are used (or the scene in which they are used, if the task was launched from by a scene event).

In general, it's best to use local variables wherever possible because:

Note: multiple copies of the same task running at the same time each have their own separate copy of their local variables.

Variable Lifetime
The value a variable holds should last until Tasker is uninstalled if it is not changed by any task.
Uninitialized Variables

User-variables which have not had a value assigned do not have replacements carried out e.g. in the expression I love %fruit, if %fruit is uninitialized, the expression remains as it is, otherwise %fruit is replaced with the value.

Exception: uninitialized variables used in mathematical expressions are replaced with 0.

Variables In Plugins

Plugin developers can tell Tasker to replace variables it finds in plugin strings with their current Tasker value. If you have a plugin which doesn't support this, send the developer this URL
http://tasker.dinglisch.net/plugins.html

which has the relevant details.

Variable Arrays

Tasker supports pseudo-arrays.

They are especially useful when used with the For action, since you can perform a set of actions on each element in turn e.g. list a set of files then test each one.

Examples

If the four variables %arr1, %arr2, %arr3, %arr4 hold respectively a, b, c and d then we have an array with 4 elements. These variables can be used just like any other, however it is also possible to access them in special ways. Here are some examples:

Notes:
Creating An Array
  1. using Variable Split:
    Variable Set %arr a,b,c,d
    Variable Split %arr
    If your data has commas in it, you can separate the values with e.g. @ and specify @ also in the Variable Split action.
  2. by assigning individual elements with Variable Set:
    Variable Set, %arr3, c.
  3. using Array Push to add an initial element
  4. some other actions also create arrays for their results e.g. List Files.
Inserting Elements
Use the Array Push action.

The Fill Spaces parameter might need more explanation. It is only relevant if one or more of the array elements are undefined. As an example, if we have the array elements %arr1 and %arr3 containing apple and banana:

Removing Elements

Use the Array Pop action. Note the difference between Array Pop and Variable Clear: Pop reduces the number of elements in the array, while Clear merely changes elements to undefined.

Example: if we have the array elements %arr1, %arr2, %arr3 containing apple,pear and banana:

Deleting An Array
Use Array Clear.

In most cases you could also use Variable Clear %arr* with Pattern Matching checked, but that would also delete variables called e.g. %arrTOODEETOO so Array Clear is safer.

Array Efficiency
Arrays are intended for convenience when processing high-level data, not for e.g. processing astronomical data. Doing thousands of array actions will likely take several seconds (although mostly due to the housekeeping work done by Tasker in-between each action rather than due to the array operations themselves).

In terms of storage efficiency, they are also fairly hopeless. You probably do not want to store tens of thousands of items in an array.