()

From PenguinMod Wiki (Official)
() (Lists)
Jump to navigation Jump to search

The () block is a reporter block in the Lists category that reports all of the items in the list. It originates from Scratch.

To rename and delete lists, this block can be right clicked (held on mobile). Lists can also be changed to other lists in the same way, by clicking the wanted name (these are features from Scratch). For the former, the block must be right clicked in the block palette, and for the latter, the block must be right clicked in the scripts area:

This is similar to the () Variables block.

Functionality in Scratch and TurboWarp

In Scratch, if the items are all detected as 1 character (and not numbers), then there will be no spaces in between the items. Otherwise, there will be spaces. For example, if you do:

delete all of [my list v]
add [1] to [my list v]
add [2] to [my list v]
add [3] to [my list v]

This block would report "123". However, if you had:

delete all of [my list v]
add [1] to [my list v]
add ((2) + (0)) to [my list v]
add [3] to [my list v]

This would report "1 2 3" instead because it detects the 2 as a number. This behavior was changed in TurboWarp (meaning the change also applies to PenguinMod), and both cases report "123", but the other case of items not having exactly 1 character remained the same.

Workaround

This block can be worked around by using (note: a variable is needed):

define report list
set [include spaces] to [false]::#0869c2
set [result] to []::#0869c2 //this is blank
for each item [var v] in [list v] {
if <(length of (var)) ≠ [1]::operators> then
set [include spaces] to [true]::#0869c2
end
}::list
for each item [var v] in [list v] {
set [result] to (join (get [result]::#0869c2) (var))::#0869c2
if <(get [include spaces]::#0869c2)::operators> then
set [result] to (join (get [result]::#0869c2) [ ])::#0869c2 
end 
}::list //the 2nd input is a space in the if statement
return (get [result]::#0869c2)::custom cap

To bypass the use of a variable, a temporary variable can be used to index over the list.