- This article is about the Variables block. For other uses, see Set () Effect to () (disambiguation).
Set () to () | |
set [ v] to () | |
Category | Variables |
Type | Stack |
Introduced in | 1.0 |
The set () to () block is a variables block and a stack block. The block will set the specified variable to the given value: a string 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. Instead, there was an instance of it for each variable, like this: set var to ()::variables
Example Uses
When a project 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
when [0 v] key pressed reset timer play sound (space ripple v) set [x v] to [0] set [y v] to [0]
- Choosing a level number
when [r v] key pressed ask [What level do you want?] and wait if <<(answer) > [0]> and <(answer) < ((levels) + (1))>> then set [level v] to (answer) end
- Setting a value for a math formula
set [r v] to (answer) say ((((4) / (3)) * (pi)) * ((r) * ((r) * (r))))
Workaround
- Main article: List of Block Workarounds
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.
change [variable v] by ((amount) - (variable))
See Also
() • Set () To () • Change () By () • Show Variable () • Hide Variable () • See also: List BlocksMore blocks...
|