A list (also called an array in other programming languages) is a tool that can be used to store multiple pieces of information at once. It can also be defined as a variable containing multiple other variables. A list consists of a numbers paired with items. Each item can be retrieved by its paired number. List blocks can be found in the Data blocks palette.
- Main article: List Blocks
The following blocks can be used to program lists:
add [thing] to [list v]— Adds an item to a list
delete (1) of [list v]— Deletes a chosen item of a list
insert [thing] at (1) of [list v]— Inserts an item at a chosen point in a list
replace item (1) of [list v] with [thing]— Replaces an item in a list with a new item
(list :: list)— A reporter block with few uses; however, this can be used as a Stage Monitor
(item (1) of [list v])— A reporter block that reports what text an item in a list contains
item # of [thing] in [list v]— Reports the index in a list where an item first appears
(length of [list v])— A reporter block that reports how many items a list contains
<[list v] contains [thing] ?>— A boolean block that checks if a list contains a given string.
show list [list v]— Shows the specified list's stage monitor
hide list [list v]— Hides the specified list's stage monitor
Items can be added to or deleted from a list manually or by programming. Holding down shift and pressing enter on a list results in a new entry above the previously selected entry, and pressing enter without the shift key creates a list entry below the previously selected one. They can also be added by right-clicking the list, clicking 'import', and selecting a plain .txt or Comma Separated Values file. Each line in the file will become a new item in the list.
They can also be exported in the same way; however, it is not possible to do so if the list has a name which is unsupported in the user's operating system. In Windows, lists using question marks (?), asterisks (*), angle brackets (< >), pipes (|), a colon (:), a space ( ), or any ASCII control character cannot be exported with Scratch. The first time the export button is pressed for this type of list, nothing will happen; following the second click, the import/export menu will close. The allowed characters will vary between operating systems.
Limits on List Size
In previous versions of the Scratch editor, there is no limit to the length of an item or the number of items a list can hold, apart from an amount sufficient to crash Scratch. However, in old versions of the online editor, a project may have been rendered unable to save online if a list took too long to upload, because Scratch returns a network error after about 30 seconds. This happened at around 300,000 list items.
Some example uses for lists are as follows:
- Encoding/Decoding strings
- Artificial Intelligence
- Recording multiple values
- Conserving variables
- Saving and loading data
More Complex Uses
- Storing user-input data in Operating System simulations
- Storing AI data in games
- Allowing users to re-create past inputs
Copy and Pasting
Because text in lists can be copied and pasted into text documents, and the data in lists can also be exported or imported, lists can be used to create save systems (along with the Ask () and Wait block).
- Main article: Cloud Data
Cloud lists were an experimental feature in alpha and beta versions of Scratch 2.0. However, they were disabled when Scratch 2.0 was released. The values of cloud lists were stored on the Scratch servers; this was the only difference between them and regular lists. When a cloud list got updated, it did so across all copies of the project. This makes cloud lists ideal for things like public high score lists. Many users wanted cloud lists to come back because it would make coding easier for them.
- Main article: Casting
Lists are cast to numbers and strings with a set of explicit rules depending on its contents.
The List Editor is a feature that allows you to edit lists. It is only avalible inside the project editor. Use it by clicking on a list item and typing in the new list item. You can also delete an item by clicking the "X" at the right and add an item by clicking the "+" at the bottom left of the list area.
The list editor can be used to make Programming languages in Scratch by importing a
*.txt file into the list. It is also useful when a project needs users to edit a list. The list editor is not as widely used as many other features such as Say and Ask. Many Scratchers do not know about the list; therefore, not many projects use it.
The list editor is also useful in text editors as creating a full text editor in Scratch is almost impossible because of the limitations of what characters can be used in the Key () Pressed? block. Text editors using list editors are easy to code as the project just has to access the list item.
The list editor has many limitations, which is why it is not widely used. It can only be used in the project editor, which means users can see all the code and edit it. Its use of Scratch features also means that it is hard on the user and is not customizable at all. List editors also do not have the best user interface, and it is often misleading for the user. Because of this, very few projects use the list editor and it is a very little-known feature.
- Fibonacci Generator by makethebrainhappy
- FruitcraftRPG by Wodunne
- Random Level Generator by poopo
- Scratch Memory by spaceguy12
From the time lists were introduced, many users requested two new blocks,
hide list [list v] and
show list [list v]. Due to such high demand, they were introduced in Scratch 2.0.
Some users have suggested adding two-dimensional, or even multidimensional, lists. However, the Scratch Team has rejected that suggestion, stating that it would be too complicated for a programming language meant for beginners.