Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: IndieBoy on Tue 17/02/2009 19:41:47

Title: Mouse Over GUI, Help/Question SOLVED
Post by: IndieBoy on Tue 17/02/2009 19:41:47
I am trying to run a script when the mouse is over a listbox GUI. So what I tried to do was this:

if (gActions.X<=mouse.x<=gActions.Width && gActions.Y<=mouse.y<=gActions.Height)
    {
      TC=0;
    }
else
    {
      TC=1;
    }

Which doesn't work.
Why can't I treat GUI.width/GUI.height as an int? I am changing the size of the GUI as I am adding more things to the list box, but this code is in repeatedly_execute so that shouldn't matter. Or do I need to make a seperate gui_x, gui_y ints and keep track of the width and height myself? I know this would be possible and a little annoying to do, but I am a little confused why I can't use GUI.width/GUI.height in the same manner?

Unless I am making a very silly mistake with my script..
Title: Re: Mouse Over GUI, Help/Question
Post by: Trent R on Tue 17/02/2009 19:54:57
Why not use GUI.GetAtScreenXY?

Modified the code from the manual:
GUI *theGui = GUI.GetAtScreenXY(mouse.x, mouse.y);
if (theGui == gAction) {
  TC=0;
}
else {
  TC=1;
}



As for your if-statement, I'm not sure you can use x<y<z. I think you have to break those up with &&.


~Trent
Title: Re: Mouse Over GUI, Help/Question
Post by: IndieBoy on Mon 23/02/2009 19:58:27
Sorry for the late reply, just I haven't had much of a chance to play around with it.
I forgot to mention that the GUI is called by a right click at the mouse(x,y) so the exact cordinates of the GUI changes all the time. So I'm pretty stuck trying to think of how to make an if statement where the mouse is over the GUI.
At the moment I have two ints, MOUSE_X and MOUSE_Y that are basically the width of the gui + the intial mouse x-cord and the height of the gui + the intial mouse y-cord.
So I have a code like this in repeatly execute:

if (gActions.X<=mouse.x && mouse.x<=MOUSE_X && gActions.Y<=mouse.y && mouse.y<=MOUSE_Y)
    {
       TC=1   
    }

But this still doesn't want work. Is there a limit in how many things you can have in an if statement?

:'(
[/s]

All is fine now :D