Replace Item () of () with ()
2.0 Replace Item () of () with ().png
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; in other words, it changes the item's content to the given text.

Example Uses

If an item has to change its content, this block will do the job.

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 v) of [School Records v] with (Relay Time)
  • Adding characters onto an already-existing item
replace item (1 v) of [list v] with (join (item (1 v) of [list v]) (characters)) //"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 (item) at (item #) of [list v]

See Also