Lists

The same rules apply for lists as for variables regarding **for all sprites** and **for this sprite only**.

Declaration

Operations

Add item to list

Delete item from list at index

Delete all items from list

Insert item at index in list

Replace item at index in list

Get item at index in list

Get index of item in list

Get length of list

Check if item is in list

Show/Hide List Monitor

Get random/last item in list

Compound Assignment

List Data

Initial data for lists can be stored inside the project. This behaves the same way loading text files into lists works in the Scratch editor. In addition to loading text files, you can also load data from various scripts and commands. This is useful for creating look-up tables or loading data from images or videos.

Loading data from text files

Each line in the text file will be added to the list as a separate item.

Loading data from bash script

The bash script enclosed in triple-backticks will be executed, and the standard output will be stored in the list, one item per line. The working directory will be set to the project directory.

Loading data from any other program

The name of the program may be specified before the triple-backticks. This program will be executed with the standard input set to the script enclosed in the triple-backticks. The standard output will be stored in the list, one item per line. The working directory will be set to the project directory.

Any program that accepts input from stdin and outputs to stdout can be used.

For example, to load data from a python script:

Let's say that your script converts a file `DEPENDENCY.txt`. You wish to only

re-run the script if the file `DEPENDENCY.txt` has changed. We can use stat

to get the last modification time of the file.

struct vec3d { x, y, z };

list vec3d points = file ```file.txt```;

10

20

30

40

50

60

[

vec3d {

x: 10,

y: 20,

z: 30

},

vec3d {

x: 40,

y: 50,

z: 60

}

]