In other languages

Help the wiki!

The Scratch Wiki is made by and for Scratchers. Do you want to contribute?

Learn more about joining as an editor!

See discussions in the Community Portal

List

(Redirected from Lists)

An image of a list and example content

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.[1]

A list consists of items, each of which work somewhat like a variable, but with differences.

List blocks can be found in the Data blocks palette.

List Blocks

Main article: List Blocks
All of the list blocks.
The following blocks can be used to program lists:

Items

An image of an empty list

Items can be added to a list manually or by programming. 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. 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.

Example Uses

Some example uses for lists are as follows:

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 copy 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).

Cloud Lists

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.

Casting

Main article: Casting

Lists are cast to numbers and strings with a set of explicit rules depending on its contents.

Example Projects

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 included in Scratch 2.0.

References

  1. http://scratchforums.blob8108.net/forums/viewtopic.php?id=34284&p=212#p1258287
  • This page was last modified on 19 December 2014, at 21:07.