(Redirected from Replace Item () of () With ())
Replace Item () of () with () | |
replace item () of [ v] with () | |
Category | Variables |
Type | Stack |
Introduced in | 1.3 |
The Replace Item () of () with () block is a List block and a Stack block. The block replaces the specified item with the last input. It was introduced in Scratch 1.3.
Example Uses
Some common uses of the Replace Item () of () with () block:
- Changing an item (for example, replacing an object in a list of objects)
ask [What item would you like to change in the grocery list?] and wait set [item v] to (answer) ask [What would you like to change it to?] and wait set [new food v] to (answer) replace item (item) of [grocery list v] with (new food)
- Rewriting a list without deleting all the items and creating new ones
say [Oops, I got the wrong grocery list! I need to get a new one.] for (3) secs set [item v] to (0) repeat (length of [grocery list v]) change [item v] by (1) replace item (item) of [grocery list v] with (item (pick random (1) to (5)) of [Foods v])
- Changing a record of certain statistics
say [And Mike crosses the finish line! This is a new record for the 100 meter relay!] for (4) secs replace item [5] of [school records v] with (relay time)
- Adding characters onto an already-existing item
replace item [1] of [list v] with (join (item [1] of [list v]) (. )) //"characters" is the new letters
- Recording positions of individual clones
when I start as a clone set [id v] to (total clones) add [] to [clonesX v] forever if <key (left arrow v) pressed?> then change x by (-2.5) end if <key (right arrow v) pressed?> then change x by (2.5) end replace item (id) of [clonesX v] with (x position)
Workaround
- Main article: List of Block Workarounds
This block can be replicated with the following code:
delete (item) of [list v] insert (. . .::grey) at (item) of [list v]