This article is about the block. For more information on the value this block reports, see Mouse X (value).
Mouse X
mouse x
Category Sensing
Type Reporter

The Mouse X block is a Sensing block and a Reporter block. The block holds (reports) the mouse-pointer's current Mouse X.

Note Note: This block will report -240 or 240 if the mouse is to the left or right of the stage.

Example Uses

As this block reports where the mouse-pointer's current location, it is useful in sensing things with the mouse.

Some common uses for the Mouse X block are:

  • Performing a different action depending on where the mouse is:
when [space v] key pressed
if <(mouse x) > [100]> then
repeat (10)
change [ghost v] effect by (10)
end
wait (1) secs
clear graphic effects
else
change y by (50)
wait (0.5) secs
change y by (-50)
end
  • Creating a virtual slider:
forever
if <mouse down?> then
set x to (mouse x)
end
end
  • Determining the mouse's location with the Mouse Y block:
forever
say (join (mouse x) (join [, ] (mouse y)))
  • Snapping to a Grid
when green flag clicked
forever
set x to ((round ((mouse x)/(tile length))) * (tile length))
set y to ((round ((mouse y)/(tile height))) * (tile height))

Workaround

Main article: List of Block Workarounds

This block can be replicated with a sprite dedicated to finding the X position of the mouse:

forever
 go to (mouse-pointer v)
 set [Mouse X v] to (x position)

See Also

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