(Redirected from Lists)
A list (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
- Add () to () — Adds an item to a list
- Delete () of () — Deletes a chosen item of a list
- Insert () at () of () — Inserts an item at a chosen point in a list
- Replace Item () of () With () — Replaces an item in a list with a new item
- () — A reporter block with few uses; however, this can be used as a Stage Monitor
- Item () of () — A reporter block that reports what text an item in a list contains
- Length of () — A reporter block that reports how many items a list contains
- () Contains () — A boolean block that checks if a list contains a given string.
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 an entry above the previously selected entry. new 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 be an item in the list. They can also be exported in the same way.
Limits on list size
There is no limit to the length of an item or the amount of items a list can hold, apart from an amount sufficient to crash Scratch. However, you may not be able to save a project online if your list takes too long to upload, because Scratch will return a network error after about 30 seconds. Few lists need to contain that amount of information, but a dictionary of 350,000 English words may fail to save when 250,000 words would succeed.
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.
- Main article: Casting
Lists are cast to numbers and strings with a set of explicit rules depending on its contents.
- Fibonacci Generator by WeirdF
- 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 included in Scratch 2.0.