Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Darth Mandarb on Mon 19/01/2004 00:44:57

Title: CursorMode Variable?
Post by: Darth Mandarb on Mon 19/01/2004 00:44:57
I have certain hotspots that trigger a different cursor mode when you MouseOver them.

Since there is not a command for 'When Mouse moves Off' of a HotSpot what I have done is surround all cursor changing hotspots with one large hotspot that changes the cursor back.  The problem is, I am having to SetCursorMode(0) and I don't want that because if you're on 'Talk' when you do the mouseOvers you end up on Walk after you cross over them.

Is there a command to switch to the last used cursor mode?  So that when I move my mouse off the hotspot (onto the surrounding hotspot) it'll switch back to the last cursor mode used before the change?  I tried SetCursorMode(-1) but that didn't work.

Something like LastCursorMode or RestoreCursorMode?

I was going to try just changing the cursor graphic but if you're on 'Walk' mode, the interactions with the Hotspots won't work 'cause they're "AnyClick" actions and those get ignored by walk.  Right?

Man, I hope this makes sense to you guys ;)

Thanks!

])]V[
Title: Re:CursorMode Variable?
Post by: Wolfgang Abenteuer on Mon 19/01/2004 00:56:43
Couldn't you just assign a variable to each cursor mode when you move over the hotspot?  Like:

if (GetCursorMode() == MODE_WALK) {
 prevcursor = 1;
}
else if (GetCursorMode() == MODE_LOOK) {
 prevcursor = 2;
}
//etc.
SetCursorMode(#);

Then, when you move off of that hotspot (or rather, on to the hotspot surrounding it):

if (prevcursor == 1) {
 SetCursorMode(MODE_WALK);
}
else if (prevcursor == 2) {
 SetCursorMode(MODE_LOOK);
}
//etc.

Would that work?

~Wolfgang
Title: Re:CursorMode Variable?
Post by: Ishmael on Mon 19/01/2004 12:20:19
I prefer:

when chaging the cursor mode to something:

int prevcur = GetCursorMode();
SetCursorMode(0);

and when changing back:

SetCursorMode(pervcur);
Title: Re:CursorMode Variable?
Post by: Darth Mandarb on Mon 19/01/2004 18:49:09
Thanks guys!

That's just what I was thinking, just wasn't sure how to do it!

])]V[
Title: Re:CursorMode Variable?
Post by: Darth Mandarb on Wed 21/01/2004 10:00:46
Well ...

I can't seem to get it to work.

Here's what happens:

When the mouse moves over a hotspot I do 'Run Script'

EnableHotspot([color=aa0000]6[/color]); [color=00aa00]// THIS WILL BE EXPLAINED SHORTLY[/color]
int prevcur = GetCursorMode();
if (character[JP].y > 100) {
   SetLabelText(5,0,"DO THIS");
   SetCursorMode(8);
      return;
     }  else
   SetLabelText([color=550000]5,0[/color],"DO THAT");
   SetCursorMode([color=550000]9[/color]);

Now, the EnableHotspot(6) is an all-encompassing hotspot that surrounds all other hotspots and is used as my mouseOut effect.  So when you move the mouse off of hotspot 1, you'll hit hotspot 6 (it's impossible to not hit it)

When you mouseOver hotspot 6 it 'Run Script's this code:

SetLabelText([color=550000]5,0[/color],"");
SetCursorMode(prevcur);
DisableHotspot([color=550000]6[/color]);

When I try to save the room/game I get this:
Compile Error
There was an error compiling your script.  The problem was:
In: 'Main Script'
Error (line 161): undefined symbol 'prevcur'

Soooo ...

Then I tried this instead:

// In the mouse over script for hotspot 1
SetGlobalInt(100,GetCursorMode());

then, in the mouseover script for hotspot 6
SetCursorMode(GetGlobalInt(100));

Now, neither of the latter 2 gave an error, but neither did they work.

So how do I do it??

thanks again,
darth
Title: Re:CursorMode Variable?
Post by: a-v-o on Wed 21/01/2004 10:27:00
prevcur should be defined outside of the function in the room script. Also it should be set only once, because otherwise it is at first set to the old cursor mode, but then to 8 or 9, so that the old cursor mode gets lost:

int prevcur = -1;

function hotspot....
{
int newcur;
if (character[JP].y > 100)
{
   SetLabelText(5,0,"DO THIS");
   newcur = 8;
}
else
{
  SetLabelText(5,0,"DO THAT");
   newcur = 9;
}
 int curcur = GetCursorMode();
 if (prevcur < 0)
 {
   prevcur = curcur;
   SetCursorMode (newcur);
   EnableHotspot (6);
 }
}

function hotspot_6....
{
 SetLabelText(5,0,"");
 SetCursorMode(prevcur);
 prevcur = -1;
 DisableHotspot(6);
}

This will only work if each hotspot is surrounded by hotspot 6, so that there is no direct way to get from a hotspot to another. If you have hotspots side by side to each other without hotspot 6 between them, ask again.

EDIT: Ryukage will explain below how you get prevcur into the room script outside the functions.  ;D
Title: Re:CursorMode Variable?
Post by: Ryukage on Wed 21/01/2004 10:27:31
You're defining prevcur as a local variable, so it doesn't exist anymore once the Run Script finishes executing.  You need to go to the main room properties page and click the "edit room script" button so that you can see the whole room script instead of just one function, and add prevcur as a global variable so that it will exist as long as the room is in memory.

EDIT: Heh, a-v-o beat me to it.
Title: Re:CursorMode Variable?
Post by: Darth Mandarb on Thu 22/01/2004 02:13:22
a-v-o & Ryukage - Thanks guys!

There was a lot more involved (but you didn't know that 'cause I didn't include it!)

But I could get it to work the first time you were on the screen.  However, if you left the screen and then came back it was malfunctioning.  I was pulling my hair out trying to figure it out and finally what I did was put a 'Run Script' in the (before fadein) area that resets prevcur = -1 and that did the trick.

Yay!  I figured it out on my own!

Thanks for all your help people!  Wait till you see how this is used!  It's quite awesome!

again, thanks,

])]V[
Title: Stumped Again!!!
Post by: Darth Mandarb on Thu 22/01/2004 09:57:04
EDIT - I just stumbled across the wonderful SetMouseCursor(); command.  All the below is no longer necessary, but I'm leaving it in here 'cause I spent so much time formatting it all prettily!  And you can see how cool my GUI looks :)

What I did to fix my problem ...

When the GUI is on I SetMouseCursor(6); then, on mouse off I SetDefaultCursor();  That did the trick!


==============<   Original Message  >==================

Thanks for all your help so far ... but something else just came up.

First, a question:
Is it a bad idea to put conditional code in the Global Script 'Repeatedly Execute' area?
ex: if (mouse.x < 5) { GUIOn(8); }

Second, my dilemma:
I have a GUI that pops up based on the x coordinates, rather than Y as is available through the editor.  (I wanted a side mounted GUI rather than top mounted).  It looks like this:
(http://www.twin-design.com/thehouse/graphics/thenewgui.gif)

So here is what I did ...

In the repeatedly execute
[color=550000]if (mouse.x < 5) {
GUIOn(7); // this is the background GUI (w/ transparency)
GUIOn(8); // this is the overlay GUI (with all the buttons/options)
SetCursorMode(6); // just the pointer
}

if (mouse.x > 80) { // meaning you're no longer over the GUI
if (IsGUIOn(8)==1) {
SetCursorMode(0);
}
GUIOff(7);
GUIOff(8);
}[/color]

This works, BUT, when you mouseOff the GUI it sets your cursormode back to Walk.

So here's what I tried next ...

In the repeatedly execute
[color=550000]int cc;
if (mouse.x < 5) {
cc = GetCursorMode();
GUIOn(7);
GUIOn(8);
SetCursorMode(6); // just the pointer
}

if (mouse.x > 80) { // meaning you're no longer over the GUI
if (IsGUIOn(8)==1) {
SetCursorMode(cc); // only changes cursormode back IF gui(8) is on
}
GUIOff(7);
GUIOff(8);
}[/color]

This, to me, makes sense.  But it doesn't work.  I tried moving the int cc; to another part of the script, but then it gives me 'invalid token' error when I try to run it.

I suspect I'm doing the SetCursorMode(cc); part correctly, just that I'm not defining it right.

Thanks for your (continued) help guys!

])]V[
Title: Re:CursorMode Variable?
Post by: Pumaman on Sat 24/01/2004 20:00:56
Your original request looks similar to this one:
http://www.agsforums.com/tracker.php?action=detail&id=40

Its been on my to-do list for a while, I'll try to get round to it at some point.