From Test-Scratch-Wiki
- For the Operators block with the same name, see () of () (Operators block).
() of () | |
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:
- X Position
- Y Position
- Direction
- Costume/Backdrop number
- Size
- Volume
- Variables local to the specified sprite
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:
Also, as of Scratch 1.4, the SpriteName 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. 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:
- 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 [Sprite2 v]) = (target)>
- Checking volume to adjust a sprite's own volume accordingly
set volume to ([volume v] of [Sprite2 v])%