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)
  • 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.