Problem with MOUSESTATE

Previous topic - Next topic

dijster

Not sure what is wrong as it's worked fine before but now I get an error when I use the MOUSESTATE command.
I tried just the sample in the help document: -
Code (glbasic) Select
WHILE TRUE // Endless loop
  LimitMouse(100, 100, 400, 300)
  PRINT "<=", mx, my // <-- THE ERROR IS ON THIS LINE
  IF b1 THEN END
  SHOWSCREEN
WEND

// ------------------------------------------------------------- //
// -=#  LIMITMOUSE  #=-
// MOUSESTATE mx, my, b1, b2 (GLOBAL)
// With limiting of the area
// ------------------------------------------------------------- //
FUNCTION LimitMouse: minx, miny, maxx, maxy
  // These variables are defined LOCAL:
  // minx, miny, maxx, maxy
  MOUSESTATE mx, my, b1, b2
  IF mx<minx THEN mx=minx
  IF mx>maxx THEN mx=maxx
  IF my<miny THEN my=miny
  IF my>maxy THEN my=maxy
  SETMOUSE mx, my
ENDFUNCTION // LIMITMOUSE


and I get the following error: -
"test.gbas"(3) error : variable is not explicitly defined : mx

I was using the new v8 beta, so I uninstalled it and installed the current version 7.301 and I still get the same error.
Any help is appreciated, thanks
DIJ

Moru

You need to define "mx" and "my" global like this:

Code (glbasic) Select
GLOBAL mx, my, b1, b2

dijster

I've written a few games previously and didn't need to define them globally before.
It works now that they are defined.
Thanks for your help

Moru

In options there is a checkbox for "Explicit declarations" If this is on, you have to declare everything. This is a little cumbersome but makes programming easier in the long run.