Variables are not limited to one element. They can contain many elements — numbers, texts, other variables (or rather their values) — in a structure called a list. Run this script:
♥list = Adam❚Eva❚John❚Mary dialog ♥list
In the resulting dialog box you will see four names and two numbers contained in the
♥list variable. They are separated with another special character:
❚ (available by pressing Ctrl+\ or selecting it from the
Insert menu). This separator tells the robot that this is a list and shows where its elements are.
Lists are a very convenient storage for various data, since you can use just some of their elements if needed. For example, run this script:
♥list = Adam❚Eva❚John❚Mary dialog ♥list⟦2⟧
The dialog displays only
Eva. It's because of
⟦2⟧ parameter added to the
♥list variable at the end of the code. The number inside double brackets
⟧ (available by pressing Ctrl+[ or selecting it from the
Insert menu) is called index and points to a specific element in a list. In this case, the second element —
Eva. Experiment replacing
2 in the code above with other indices.
count between the double brackets and run the script:
♥list = Adam❚Eva❚John❚Mary dialog ♥list⟦count⟧
You will see
4 in the resulting dialog box, because
count, as its name implies, counts elements in a list.
The next lesson will show you more operations you can perform on lists.