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.

Set () to () (1.0).png

用法示例

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


Note Note: 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))

参见

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