(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. Although lists are similar to 1 dimensional arrays, meaning that items can not be stored in a theoretical grid, unlike most other programming languages, lists can be made to function like arrays. In fact, though called lists, they are actually resizable arrays for all practical purposes.
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 a list manually or by programming. Items can be deleted in the same manner: manually or by programming. 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, there are few cases in which a list needs to contain that amount of information.
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
- Main article: Cloud Data
Cloud lists are a coming feature in Scratch 2.0. The values of cloud lists are stored on the Scratch servers; this is the only difference between them and regular lists. When a cloud list gets updated, it does so across all copies of the project. This makes cloud lists ideal for chatroom projects, for example.
- 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.