(Redirected from Lists)

For more information, see List on Wikipedia.
This article is about the feature. For the section of blocks, see List Blocks.
A list containing 6 items.

A list is an ordered collection of items. It can be used to store multiple pieces of information at once. Each item has an index number, starting from 1 and counting upwards. Items can be retrieved and modified by their index. Lists are similar to arrays (found in other programming languages).

List blocks can be found in the variables blocks palette. They were first introduced in Scratch 1.3.

List Blocks

Main article: List Blocks

The following blocks can be used to program lists:

Example Uses

Some example uses for lists are as follows:

  • An inventory of items in games
  • Encoding/decoding strings by storing characters as list items
  • Storing a grid of tiles in a tile-based game
  • Storing the locations and other properties of entities in a game
  • Recording events that occurred for debugging
  • Storing geometry for 3D projects

Copy and Pasting

Because text in lists can be selected and copied, lists can be used to create save systems by letting the user copy the list content and paste it somewhere else. The Ask () and Wait block can later ask the user to paste the save to load it.

Items

Main article: Item
An empty list.

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.

Like local variables, lists that are set to "For this sprite only" are unique to each sprite or clone. A created clone will inherit the list items of its parent.

Limits on List Size

In Scratch 3.0, new items cannot be added or inserted into a list if the list already has 200,000 or more items.[1] However, there is no limit on list size when importing a list.

In previous versions of the Scratch editor, an unlimited number of items could be added to a list until Scratch crashed. 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 returned a network error after about 30 seconds.[citation needed]

List Editor

The Scratch list editor.

The list editor is a feature that allows one to edit lists. It is only available inside the project editor. Use it by clicking or tapping on a list item and typing in the new list item. One can also delete an item by clicking or tapping the "X" at the right and add an item by clicking or tapping the "+" at the bottom left of the list area or by pressing the ↵ Enter (or ↵ Return) key and resize a list by dragging the "=" at the bottom right of the list area.

Importing and Exporting

The contents of a list can be imported from a file. To do so, right-click or long-press the list, select "import", and select the file. Both plain text files and Comma Separated Values (CSV) files can be imported. Each line in the file will become a new item in the list.

To export the contents to a text file, right-click or long-press the list, select "export", and choose a place to save it to. The default file name is the name of the list. Any characters in the name that are unsupported by the operating system are replaced with underscores (_). In Scratch 2.0 this would prevent exporting.

Uses

Beyond use by the project creator, the list editor is 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.

The list editor can be used to import multi-line text, unlike the Ask () and Wait block. A programming language project can let the user import text written in an external code editor. A 3D project could also ask for the user to import a 3D model as an .obj file (a popular plain-text file format for 3D models).

Cloud Lists

Main article: Cloud Data

Cloud lists were an experimental feature in alpha and beta versions of Scratch 2.0.[citation needed] 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.[2][better source needed] Cloud lists are currently a rejected suggestion.[3] However, they can be replicated by encoding and decoding cloud data.

Requests

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.

Users have suggested adding multidimensional lists or arrays[4]. However, the Scratch Team has rejected that suggestion, stating that it would be too complicated for a programming language meant for beginners.[5]

Example Projects

See Also

References

Cookies help us deliver our services. By using our services, you agree to our use of cookies.