(Redirected from () (Lists block))
() | |
(list::list) | |
Category | List |
Type | Reporter |
Introduced in | 1.3 |
- This article is about the list block. For the variables block used to report variable values, see () (Variables block).
The () block is a List block and a Reporter block. The block simply reports the items of its list as a string. Whenever a list is created, a version of the block appears with the list's name on it; this results in a version of this block for every list. If all of the items in a list are single characters, nothing is put between the items.[note 1] Otherwise, a space is put between each pair of items.
This block can be displayed as a Stage Monitor, but the monitor will show the items in the list on separate lines, instead of all together.
Example Uses
The List reporter block is used infrequently;[citation needed] most information needed can be accessed by using other reporters for the list. However, here are a couple uses for this block.
Some common uses for the () block:
- Join separate characters/words together:
say (sentence::list)
- Setting a variable to the value of this block so that a list local to a sprite can be transferred:
set [unlock v] to (list::list)
Workaround
- Main article: List of Block Workarounds
This block can be replicated with the following code:
set [count v] to [0] set [all are 1 v] to [true] repeat until <<(all are 1) = [false]> or <(count) > (length of [list v])>> change [count v] by (1) if <(length of (item (count) of [list v])) > [1]> then set [all are 1 v] to [false] end end if <(all are 1) = [true]> then set [report v] to [] set [count v] to [0] repeat (length of [list v]) change [count v] by (1) set [report v] to (join (report) (item (count) of [list v])) end else set [report v] to (item (1) of [list v]) set [count v] to [1] repeat ((length of [list v]) - (1)) change [count v] by (1) set [report v] to (join (report) (join [] (item (count) of [list v]))) end end
Bugs
Due to the nature of the Scratch interface, it was possible to create an input on a List block by entering %m, %n, or %s. This was patched in Scratch 2.0 v423.
Before Scratch 3.0 was released, lists weren't able to be renamed, even though variables could be.
Notes
- ↑ If any items are numbers, such as
add ((1) + (0)) to [list v]
, rather than a string, likeadd [1] to [list v]
, then there will be spaces between the values even if all of the numbers are single-digit numbers. See: https://github.com/LLK/scratch-gui/issues/6538