This article is about the block. For more information on the value this block reports, see Y Position (value).
Y Position
y position
Category Motion
Type Reporter
Introduced in 11Jun04 (0.x)

The Y Position block is a Motion block and a reporter block. The block holds its sprite's Y position. This block can be displayed as a Stage Monitor.

Example Uses

As this block reports its sprite's Y position, it can be used when a script needs to know its parent sprite's Y position. There are many cases of this. For example, one could use the block to detect how far up the user is on the screen.

Note Note: These scripts only work in sprites, as the stage does not hold any Y value.
forever
  wait until <(y position) > [220]>
  change [Hits v] by (1)
end

Another use is setting values based on a movable slider. The script sets the value to the slider's Y position.

set [sliderValue v] to (y position)

Other common uses are:

  • Comparing the Y position with a record to check for movement
when green flag clicked
set [y_pos prev v] to (y position)
forever
if <not <(y_pos prev) = (y position)>> then
say [My Y position moved!] for (2) seconds // if the y position moved, say something
set [y_pos prev v] to (y position)
end
end
  • Constantly storing a sprite's Y movement so it can be re-enacted later
when green flag clicked //script only works in a sprite
delete all of [x positions v]
delete all of [y positions v]
say [Move your mouse and I will reenact the movement!] for (2) seconds
say [Go!] for (1) seconds
repeat (50)//records 50 coordinates at a rate of one for every 0.1 seconds
    go to (mouse-pointer v)
    add (x position) to [x positions v]
    add (y position) to [y positions v]
    wait (0.1) seconds
end
set [counter v] to [1]
say [I will reenact it for you now!] for (2) seconds
repeat (50)
    go to x:(item (counter) of [x positions v]) y:(item (counter) of [y positions v])
    wait (0.1) seconds
    change [counter v] by (1)
end
when green flag clicked
forever
change y by (y position)
end

Workaround

Main article: List of Block Workarounds

The block can be simply replicated with the following block:

([y position v] of (sprite v))

However, as this workaround requires the () of () block, it cannot be used to get the Y position of the current sprite and must be done from another sprite, unless this workaround is used:

([y position v] of (join [sprite][]))

See Also

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