"() of ()" redirects here. For the Operators block with the same name, see () of () (Operators block).
() of ()
[ v] of ( v)
Category Sensing
Type Reporter
Introduced in 1.2

The () of () block is a Sensing block and a Reporter block. The block will report a specified value of the specified sprite or the stage.

Below are the values that can be reported:

If the block is used on a sprite which has clones, the reported value will be of the original sprite, and never of the clones.[1] This makes it impossible to access information about clones using this block.

If there is nothing in the second drop-down, or if a sprite that was deleted or is non-existent is in the second drop-down, it reports the value as 0.

Example Uses

This block allows sprites and the stage to have access to other sprites' special values. With this, projects can have a lot of connectivity between sprites.

This block renders eight blocks unnecessary (except when used by clones):

Also, Scratch 1.4 and all versions after it, the sprite name area can have an expression/variable put into it so that a script can access any other sprite's variables or properties given that sprite's name. To specify the stage, the name must be "_stage_". This is useful in projects where one wants to be able to generalize things:

set [index v] to [0]
repeat (length of [names v])
   change [index v] by (1)
   replace item (index) of [values v] with ([myVar v] of (item (index) of [names v]))

Some common uses for the () of () block include:

  • Making a sprite follow another by setting their X and Y positions to the X and Y positions of the other, plus or minus a certain amount:
when gf clicked
forever
   go to x: (([x position v] of (Sprite2 v)) - (10)) y: (([y position v] of (Sprite2 v)) - (10))
  • Waiting for a different sprite to reach a certain costume
wait until <([costume# v] of (Sprite1 v)) = (target)>
  • Checking volume to adjust a sprite's own volume accordingly
set volume to ([volume v] of (Sprite1 v))%

Workaround

Main article: List of Block Workarounds


The functionality of this block can be recreated with the following scripts:

Put this in every sprite:

when green flag clicked
forever
set [Sprite1: X v] to (x position)// Change "Sprite1" to the name of the sprite for each of these
set [Sprite1: Y v] to (y position)
set [Sprite1: Direction v] to (direction)
set [Sprite1: Costume# v] to (costume [number v]::looks)
set [Sprite1: Costume Name v] to (costume [name v]::looks)
set [Sprite1: Size v] to (size)
set [Sprite1: Volume v] to (volume)
end

And then for the stage:

when green flag clicked
forever
set [Stage: Backdrop# v] to (backdrop [number v]::looks)
set [Stage: Backdrop Name v] to (backdrop [name v]::looks)
set [Stage: Volume v] to (volume)
end

And then to call those:

set [output v] to (Sprite 1: X)

References

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