Variables
A variable is a value saved under a name. One step saves it; later steps use it by writing $
and the name in a field, or by choosing it under Saved by earlier steps in the value menu
(Step parameters).
Saving a step's result
Fill in Save result as on a step to keep what it gives back. This is the usual way to get a value: the window a step found, the text it read, the answer someone picked.
The first step reads the clipboard and saves the text as copied. The second shows it in a message
box.
Setting a variable
The Set variable chip adds a step that stores a value you type. It has three fields:
| Field | What it holds |
|---|---|
| Variable | The name. A new step gets a free name such as value or value2. |
| Value | The value, $ and another variable's name to copy that variable, or a reading from the value menu (Step parameters), such as Clipboard text. |
| Type | Text, Whole number, Number or True or false. Hidden while Value holds a reading. |
The type is what you choose, not what the value looks like: with Text, 42 is the text "42",
not the number 42. Text may be empty; the other types need a value, checked as for any field
(Step parameters).
A reading stores what it reads when the step runs, with that reading's own type, so there is no
Type to choose. Typing the reading's script name with empty parentheses, such as
ClipboardGetText(), is the same as choosing it, whatever the type. A Text value that is a
builtin call with something in its parentheses, such as WindowGetTitle($w), is stored as those
characters and not run; the form says so. To keep such a call's result, use Save result as on
that builtin's step instead.
Setting a variable that already exists replaces its value.
The value types
Every value has one of these types. The editor's words, and the script reference's:
| In the editor | In the script reference | Examples |
|---|---|---|
| Text | Text | Notepad, an empty text |
| Whole number | Integer | 0, -12, 0xB3, VirtualKey.F5 |
| Number | Real | 0.5, 2.0 |
| True or false | Bool | on / off, true / false |
| a window | Window | Target window, a window a step found |
A window can't be typed; it comes from the value menu or from a step's result. How each type counts as true or false in a condition is in Value types.
Names
A variable name:
- uses letters, digits and
_, and doesn't start with a digit; - is not
if,else,for,trueorfalse; - is case-sensitive:
Windowandwindoware two variables.
A $ you type at the start of a name is dropped, so $count and count name the same variable.
Rules to know
- Order matters. A variable exists from the step that saves it onward. The editor doesn't check that a variable is saved before it is used, or that moving steps keeps the saving step above. A variable that was never saved reads as the whole number 0.
- Variables last for one run. Each time the action runs, it starts with no variables. To keep a value across runs and restarts, use the Keep value across restarts and Get kept value steps (from All N builtins…; see How scripts run).
- A snippet has its own variables. A snippet called from an action can't see the action's variables, and the action can't see the snippet's.
- There is no arithmetic. A field takes a value or a variable, never a calculation such as
$count + 1. For that, use Script (From Steps to Script).