Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: amanta4ray on Fri 23/01/2009 17:48:08

Title: Mouse graphic doesn't change when using SaveCursorUntilItLeaves
Post by: amanta4ray on Fri 23/01/2009 17:48:08
      I have set up my hotspots to use SaveCursorUntilItLeaves for temporary exit arrows.  
Sometimes the cursor doesn't go back to the default graphic.  It either stays on that arrow or it picks up the graphic of one of the other arrows and stays on that.  
     
   When I click on something, the mouse processes it as the correct mode, walk, look, etc. and when I cycle through the cursors it seems to unstick itself and the correct graphic shows back up.  

I have checked my hotspots to make sure none overlap.   The script I use is:

              mouse.SaveCursorUntilItLeaves();
                 mouse.Mode =eModeLarrow;



                             Thanks!!

 P.S. My exit arrows are not set to standard mode.  

           

                         
               
Title: Re: Mouse graphic doesn't change when using SaveCursorUntilItLeaves
Post by: Ultra Magnus on Fri 23/01/2009 18:58:11
I had the exact same problem a while back.

I came to the conclusion that it's better to use this method instead...

function room_RepExec()
{
if (Hotspot.GetAtScreenXY(mouse.x, mouse.y) == hLeftedge) {
  mouse.ChangeModeGraphic(eModeLookat, 7);
  mouse.ChangeModeGraphic(eModeInteract, 7);
  mouse.ChangeModeGraphic(eModeTalkto, 7);
  }
else if (Hotspot.GetAtScreenXY(mouse.x, mouse.y)==hRightedge) {
  mouse.ChangeModeGraphic(eModeLookat, 8);
  mouse.ChangeModeGraphic(eModeInteract, 8);
  mouse.ChangeModeGraphic(eModeTalkto, 8);
  }
else {
  mouse.ChangeModeGraphic(eModeLookat, 2);
  mouse.ChangeModeGraphic(eModeInteract, 3);
  mouse.ChangeModeGraphic(eModeTalkto, 4);
  }
}

...where the sprite in slot 7 is the left exit arrow, 8 is the right, and 2, 3 and 4 are the defaults for each of those modes.
And you can just add an extra if for each additional exit.

Even better, if each of the exits in all of your rooms are in the same hotspot slot (i.e. hotspot1 is always the left exit and hotspot2 is always the right), then you could just put this one in global...

function repeatedly_execute()
{
if (Hotspot.GetAtScreenXY(mouse.x, mouse.y) == hotspot[1]) {
  mouse.ChangeModeGraphic(eModeLookat, 7);
  mouse.ChangeModeGraphic(eModeInteract, 7);
  mouse.ChangeModeGraphic(eModeTalkto, 7);
  }
else if (Hotspot.GetAtScreenXY(mouse.x, mouse.y)==hotspot[2]) {
  mouse.ChangeModeGraphic(eModeLookat, 8);
  mouse.ChangeModeGraphic(eModeInteract, 8);
  mouse.ChangeModeGraphic(eModeTalkto, 8);
  }
else {
  mouse.ChangeModeGraphic(eModeLookat, 2);
  mouse.ChangeModeGraphic(eModeInteract, 3);
  mouse.ChangeModeGraphic(eModeTalkto, 4);
  }
}

...instead of having to put it in each room separately.

With these, you should also make each hotspot activate with any click, rather than a specific mode.
Give one of them a try and see how it suits you.

The only thing is that you might also want to disable right-clicks while over those hotspots so the player can't change mouse mode until they come back off of them. I'm still investigating how to do that, myself.
Title: Re: Mouse graphic doesn't change when using SaveCursorUntilItLeaves
Post by: Khris on Fri 23/01/2009 19:09:04
I dealt with this here:
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=29123.msg371031#msg371031
(check the last post)
Title: Re: Mouse graphic doesn't change when using SaveCursorUntilItLeaves
Post by: amanta4ray on Fri 23/01/2009 20:46:56
  Thanks guys for the quick response and excellent suggestions...

            I'll give these a try and see how it goes..


   And yeah, it would be nice if I could just do it globally, but of course, each room
  is different.
Title: Re: Mouse graphic doesn't change when using SaveCursorUntilItLeaves
Post by: Pumaman on Fri 23/01/2009 22:49:08
Quote from: amanta4ray on Fri 23/01/2009 17:48:08
I have checked my hotspots to make sure none overlap.   The script I use is:

              mouse.SaveCursorUntilItLeaves();
                 mouse.Mode =eModeLarrow;

Where have you put that script? Make sure that there's no possibility that SaveCursorUntilItLeaves could be getting called when the mouse is already in the other mode, or it would get stuck there. Maybe something like:

if (mouse.Mode != eModeLarrow)
{
    mouse.SaveCursorUntilItLeaves();
    mouse.Mode = eModeLarrow;
}

QuoteI came to the conclusion that it's better to use this method instead...

Rather than having to paste code like that into every room, this would be much easier if you used Custom Properties -- just define some sort of "Special Mouse Cursor" custom property, and set it on the appropriate hotspots. Then, have some global code that checks the property of the current hotspots and changes the mouse cursor accordingly.
Title: Re: Mouse graphic doesn't change when using SaveCursorUntilItLeaves
Post by: amanta4ray on Sat 24/01/2009 01:00:58
  I tried both KhrisMUC and Ultra Magnus's suggestions and they seem to work fine
except for when I try to change rooms.  For some reason, my code won't run and I am stuck in that room.

             My code for SaveCursorUntilItLeaves is under Mouse moves over hotspot
               and my code to change rooms is under Any click on hotspot.

                This is the code I use to change rooms:
                               
                          player.FaceLocation(player.x+10, player.y);
                                 player.ChangeRoom(367,4,211);

         I'm not exactly sure how to set up the 'Special Cursor Property' that
              Pumaman suggested.
Title: Re: Mouse graphic doesn't change when using SaveCursorUntilItLeaves
Post by: Ultra Magnus on Sat 24/01/2009 10:57:35
Quote from: Pumaman on Fri 23/01/2009 22:49:08
Rather than having to paste code like that into every room, this would be much easier if you used Custom Properties -- just define some sort of "Special Mouse Cursor" custom property, and set it on the appropriate hotspots.

Yeah, after I read Khris' post I went back and incorporated that into my code as well.
Must admit I just simply didn't think of it before.

Now I have this in global...

int exitpoint;
export exitpoint;

                     // bit of a gap...

function repeatedly_execute()
{
  if (exitpoint==1) {
   mouse.ChangeModeGraphic(eModeLookat, 7);
   mouse.ChangeModeGraphic(eModeInteract, 7);
   mouse.ChangeModeGraphic(eModeTalkto, 7);
   }
  else if (exitpoint==2) {
   mouse.ChangeModeGraphic(eModeLookat, 8);
   mouse.ChangeModeGraphic(eModeInteract, 8);
   mouse.ChangeModeGraphic(eModeTalkto, 8);
   }
                     // snip the other 4 directions as you can see where this is going...
  else {
   mouse.ChangeModeGraphic(eModeLookat, 2);
   mouse.ChangeModeGraphic(eModeInteract, 3);
   mouse.ChangeModeGraphic(eModeTalkto, 4);
   }
}

...with import exitpoint; in global.ash.

And this in each room...

function room_RepExec()
{
if (Hotspot.GetAtScreenXY(mouse.x, mouse.y) == hLeftedge) {
   exitpoint=1;
   }
else if (Hotspot.GetAtScreenXY(mouse.x, mouse.y)==hRightedge) {
   exitpoint=2;
   }
                     // etc.
else {
   exitpoint=0;
   }
}


It also makes disabling right-click (as I mentioned/suggested earlier) easy.
I just changed if (button == eMouseRight) in the controls section to if (exitpoint==0 && button == eMouseRight).
Title: Re: Mouse graphic doesn't change when using SaveCursorUntilItLeaves
Post by: Pumaman on Sat 24/01/2009 20:12:32
Well, if you use Custom Properties then you don't even need to add any scripting to the rooms.

See here for more on Custom Properties (http://www.adventuregamestudio.co.uk/manual/Custom%20Properties.htm).
Title: Re: Mouse graphic doesn't change when using SaveCursorUntilItLeaves
Post by: amanta4ray on Sat 24/01/2009 22:06:04
   I want to thank everyone for their help with this.  

                I tweaked the code a bit and got  it working pretty good!!