Author Topic: Problem with MOUSESTATE  (Read 2922 times)

Offline dijster

  • Mc. Print
  • *
  • Posts: 23
    • View Profile
Problem with MOUSESTATE
« on: 2010-Jun-14 »
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

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1791
    • View Profile
    • Homepage
Re: Problem with MOUSESTATE
« Reply #1 on: 2010-Jun-14 »
You need to define "mx" and "my" global like this:

Code: (glbasic) [Select]
GLOBAL mx, my, b1, b2

Offline dijster

  • Mc. Print
  • *
  • Posts: 23
    • View Profile
Re: Problem with MOUSESTATE
« Reply #2 on: 2010-Jun-14 »
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

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1791
    • View Profile
    • Homepage
Re: Problem with MOUSESTATE
« Reply #3 on: 2010-Jun-14 »
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.