From Test-Scratch-Wiki

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 for 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 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]
if <key [left arrow v] pressed?> then
change x by (-2.5)
if <key [right arrow v] pressed?> then
change x by (2.5)
replace item (id) of [clonesX v] with (x position)


Main article: List of Block Workarounds

This block can be replicated with the following code:

delete (value) of [list v]
insert (item) at (value) of [list v]

See Also

Cookies help us deliver our services. By using our services, you agree to our use of cookies.