This article is about the variables block. For the list block used to report list values, see () (List block).
()
(variable)
Category Variables
Type Reporter

The () block is a Variables block and a reporter block. When a variable is created, a version of the block appears in the block palette with the variable's name on it. When used in a script, the block reports the value of the variable it corresponds to. This block can be displayed as a stage monitor.

Example Uses

This block is the primary way of retrieving a value stored in a variable. This block, and variables in general, can be used to:

  • Save/recall user input
ask [What's your name?] and wait
set [name v] to (answer)
ask [What's your favorite color?] and wait
set [favorite color v] to (answer)
say (join (join (join (join [Hi ] (name)) [, whose favorite color is ]) (favorite color)) [!])
  • Keep track of scores and currencies
if <(score) > [1000]> then
  say [ability unlocked!]
end
  • Add controllable parameters in calculations
set [width v] to [20]
set [height v] to [15]
set [area of rectangle v] to ((width) * (height))

Local Variables

The values of local variables are stored independently by each sprite or clone and can only be changed by themselves. When the variable block is used in a script, the value of the sprite or clone it is running in will be reported.

If the block is clicked in the editor, a bubble will only show the value of the sprite's variable and not any of its clones.

Workaround

Main article: List of Block Workarounds

A global variable can be accessed with

([global variable v] of (Stage v))

A local variable can be accessed with

([local variable v] of (Sprite v))

However, this workaround does not work on clones. It will always report the main sprite's value.

See Also

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