From Test-Scratch-Wiki

Set () to ()
2.0 Set () to ().png
Category Variables
Type Stack

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 and instead there was an instance of it for each variable.

Set () to () (1.0).png

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 [SpaceRipple v]
set [x v] to [0]
set [y v] to [0]
  • Choosing a level number
when [r v] key pressed
set [level v] to (pick random (1) to (20))
  • Setting a value for a math formula
set [r v] to (answer)
say ((((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.

change [variable v] by ((amount) - (variable))

See Also

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