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)
wait (1) secs
clear graphic effects
change y by (50)
wait (0.5) secs
change y by (-50)
  • Creating a virtual slider:
if <mouse down?> then
set x to (mouse x)
  • Determining the mouse's location with the Mouse Y block:
say (join (mouse x) (join [, ] (mouse y)))
  • Snapping to a Grid
when green flag clicked
set x to ((round ((mouse x)/(tile length))) * (tile length))
set y to ((round ((mouse y)/(tile height))) * (tile height))


Main article: List of Block Workarounds

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

 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.