From Test-Scratch-Wiki
變數 [ v] 設為 [0] | |
File:2.0 Set_()_to_().png | |
类别 | 变量类积木 |
形狀 | 条形积木 |
The Set () to () 积木 is a 变量类积木 and a 条形积木. The block will set the specified 变量 to the given value: a 字串 or number. In Scratch 1.2.1 and earlier, only numbers could be entered.
Prior to Scratch 1.3, this block did not have a drop-down input listing the variables and instead there was an instance of it for each variable.
用法示例
When a 专案 is started, certain variables (such as score, the current level, etc.) must be reset for the project to work correctly.
Some common uses for the Set () to () block:
- Resetting a project
當 [0 v] 鍵被按下 計時器重置 播放音效 [SpaceRipple v] 變數 [x v] 設為 [0] 變數 [y v] 設為 [0]
- Choosing a level number
當 [r v] 鍵被按下 變數 [level v] 設為 (隨機取數 (1) 到 (20))
- Setting a value for a math formula
變數 [r v] 設為 (詢問的答案) 說出 ((((4) / (3)) * (pi)) * ((r) * ((r) * (r))))
应用
- Main article: List of Block Workarounds
![]() | This workaround only works for number values. |
This block's actions can be replicated by the script segment below, where "amount" is the number you want to change it to.
變數 [variable v] 改變 ((amount) - (variable))
参见
Zho:变数类积木 | |
Zho:清单类积木 |
()
• 新增项目 () () • 删除第 () 项 () • 添加 () 为第 () 项 • 替换第 () 项于 () 成 () • 清单第 () 项项目 () • 清单 () 的项目数 • 清单 () 包含 () • 清单 () 显示 • 清单 () 隐藏更多积木… |