From Test-Scratch-Wiki
替换第 () 项于 () 成 () | |
替換第 ( ) 項於 [ v] 成 ( ) | |
类别 | 变量类积木 |
形狀 | 条形积木 |
加入於 | 1.3 |
The Replace Item () of () with () 积木 is a 清单类积木 and a 条形积木. The block replaces the specified item; in other words, it changes the item's content to the given text.
用法示例
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
詢問 [What item would you like to change in the grocery list?] 並等待 變數 [item v] 設為 (詢問的答案) 詢問 [What would you like to change it to?] 並等待 變數 [new food v] 設為 (詢問的答案) 替換第 (item) 項於 [Grocery List v] 成 (new food)
- Rewriting a list without deleting all the items and creating new ones
說出 [Oops, I got the wrong grocery list! I need to get a new one.] (3) 秒 變數 [item v] 設為 (0) 重複 (清單 [Grocery List v] 的項目數 :: list) 次 變數 [item v] 改變 (1) 替換第 (item) 項於 [Grocery List v] 成 (清單第 (隨機取數 (1) 到 (5)) 項項目\( [Foods v] \) :: list) end
- Changing a record of certain statistics
說出 [And Mike crosses the finish line! This is new record for the 100 meter relay!] (4) 秒 替換第 (5 v) 項於 [School Records v] 成 (Relay Time)
- Adding characters onto an already-existing item
替換第 (1 v) 項於 [list v] 成 (字串組合 (清單第 (1 v) 項項目\( [list v] \) :: list) 和 (characters)) // "characters" is the new letters
- Recording positions of individual clones
當分身產生 變數 [id v] 設為 (total clones) 新增項目 [] \( [clonesX v] \) 重複無限次 如果 <[向左 v] 鍵被按下?> 那麼 x 改變 (-2.5) end 如果 <[向右 v] 鍵被按下?> 那麼 x 改變 (2.5) end 替換第 (id) 項於 [clonesX v] 成 (x 座標) end
应用
- Main article: List of Block Workarounds
This block can be replicated with the following code:
刪除第 (value) 項 \( [list v] \) 添加 (item) 為第 (value) 項\( [list v] \)
参见
Zho:变数类积木 | |
Zho:清单类积木 |
()
• 新增项目 () () • 删除第 () 项 () • 添加 () 为第 () 项 • 替换第 () 项于 () 成 () • 清单第 () 项项目 () • 清单 () 的项目数 • 清单 () 包含 () • 清单 () 显示 • 清单 () 隐藏更多积木… |