Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: miguel on Wed 16/04/2008 11:21:45

Title: Hotspot problems again (need to store data)
Post by: miguel on Wed 16/04/2008 11:21:45
Ok, I need to check if the mouse is above Hotspot1 when processing a mouse button click under a GUI.
I thought it would be easy but now I get the message :
   undefined symbol 'hHotspot1' on line 436.

Here is the code:
   function Button1_OnClick(GUIControl *control, MouseButton button)
{
  if (Hotspot.GetAtScreenXY(mouse.x, mouse.y) == hHotspot1) {
cEgo.FaceLocation(mouse.x, mouse.y, eBlock);
cEgo.Say("A painting.");
mouse.SetBounds(0, 0, 0, 0);
gGui1.Visible=false;
gGui1.Transparency=50;
SetGlobalInt(1, 0);
return;
}
}


Maybe scripts 'under' this kind of functions don't reconize hotspots?
Should I use Globalints?
I'm using version 3.0
thanks in advance, I did search the forums but I didn't get what I need
Title: Re: GUI script does not reconize Hotspot
Post by: Gilbert on Wed 16/04/2008 11:31:16
I'm not quite sure, but I think as hotspots are room specific, so its Script-O-name is local to that room's script. Try to use the ID in more "global" scripts instead, like:

if (Hotspot.GetAtScreenXY(mouse.x, mouse.y).ID == 1) {
Title: Re: GUI script does not reconize Hotspot
Post by: Khris on Wed 16/04/2008 11:32:56
The problem is that hotspots are local to their rooms while button functions are defined in the global script.

You need to do:
  Hotspot*h = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
  if (Player.Room == 3 && h == hotspot[2]) {     // test for hotspot #2 in room #3
    ...


Edit: Unfortunately, adding .ID like that won't work, afaik.
Title: Re: GUI script does not reconize Hotspot
Post by: miguel on Wed 16/04/2008 11:43:25
ok, tried the globalints and it worked but it will get confusing in the future
also tried your code and it also works but I'll need to dive into it.
thanks for the quick answers.
I might have to call on your help again...
Title: Re: GUI script does not reconize Hotspot
Post by: miguel on Wed 23/04/2008 13:03:21
Hi again, I used the same post as the issues are related.
Ok, as you can see on my code that was fixed and working (thanks!) I open a gui (ggui1) when the mouse runs over a hotspot.
  - it works
  - the player then has acess to 3 actions (buttons), look, use, inventory - it works
  - on the top of the gui there is a label that returns the location name - it works BUT, can I have that locations name permanent, until the player finishes with his options?
 
  - I understand that if it's a @overhotspot@ then if the mouse isn't above one it doesn't work, so I checked the forum and found how to write into labels, I just emulated @overhotspot@  :(
  - I explored the forum again and found this code:
Game.GlobalStrings[1]=String.Format("%sa",Game.GetLocationName(mouse.x, mouse.y));
I use it when the gui is on but still no good, I understand the gui is the primary object to the mouse,
and I still can't override the mouse beeing on top of the gui

   I guess I sound very confusing but all I want is that the gui label returns the locations name and keeps it until the next hotspot is hoovered by the mouse.
Title: Re: GUI script does not reconize Hotspot
Post by: Khris on Wed 23/04/2008 14:09:22
Something like this should work:

// inside rep_ex

  if (GetLocationType(mouse.x, mouse.y) != eLocationNothing)
    labelname.Text = Game.GetLocationName(mouse.x, mouse.y);


This will only change the label's text when the mouse is moved over a new location.
Title: Re: GUI script does not reconize Hotspot
Post by: miguel on Wed 23/04/2008 20:30:04
Thanks again KhrisMuc, it worked perfectly :)
It took me all afternoon with no sucess!
You get a free beer when you get to Praia da Rocha!
Title: Re: GUI script does not reconize Hotspot
Post by: miguel on Sat 10/05/2008 22:31:53
Hi again,
I'm using this old thread because it's a related issue.

Problem:
      I've set this interface where when the mouse is over a hotspot and I right click it brings me a dialog gui;
      With your help I have managed to do it fine;
      The thing is, let's say I click on the look button,
             if the mouse is over the hotspot I get the correct interaction;
             if the mouse is on other hotspot I logicaly get its interaction;

       I know why I get this, I don't know how to store the hotspot.ID and use it when I right click.
      This is my code:
function setinterface() {
  if (GetLocationType(mouse.x, mouse.y) != eLocationNothing) {   ////KrisMuc code!!!!
   
    Label23.Text = Game.GetLocationName(mouse.x, mouse.y);
}

if ((Hotspot.GetAtScreenXY(mouse.x, mouse.y) == hotspot[0]) && (GetGlobalInt(1)==0)) {
  gGui9.Visible=false;
}
if ((Hotspot.GetAtScreenXY(mouse.x, mouse.y) != hotspot[0]) && (IsGamePaused()==0)) {
  gGui9.Visible=true;
}
if ((Hotspot.GetAtScreenXY(mouse.x, mouse.y) != hotspot[0]) && (IsGamePaused()==1)) {
  gGui9.Visible=false;
}
if (((Hotspot.GetAtScreenXY(mouse.x, mouse.y) != hotspot[0]) && (IsGamePaused()==0) && (mouse.IsButtonDown(eMouseRight)))) {
 
  if (Hotspot.GetAtScreenXY(mouse.x, mouse.y) == hotspot[12]) {
    gGui9.Visible=false;gGui1.Visible=false;
    return;
    }

  if ((mouse.y >0) && (mouse.y <180) && (mouse.x < 217)){
    gGui1.SetPosition(mouse.x-10, mouse.y-15);
    gGui1.Visible=true;
    SetGlobalInt(1, 1);
    gGui1.Clickable=true;
    gGui1.Transparency=30;
    waitforgui();
    Wait(2);
    /////int activeh = location,hotspot???
    }
  if ((mouse.y>180) && (mouse.y<240) && (mouse.x < 217)){
    gGui1.SetPosition(mouse.x,180);
    gGui1.Visible=true;
    SetGlobalInt(1, 1);
    gGui1.Clickable=true;
    gGui1.Transparency=30;
    waitforgui();
    Wait(2);
  }
  if ((mouse.y >0) && (mouse.y <180) && (mouse.x > 217)){
    gGui1.SetPosition(mouse.x-23, mouse.y-15);
    gGui1.Visible=true;
    SetGlobalInt(1, 1);
    gGui1.Clickable=true;
    gGui1.Transparency=30;
    waitforgui();
    Wait(2);
  }
  if ((mouse.y>180) && (mouse.y<240) && (mouse.x > 217)){
    gGui1.SetPosition(mouse.x-23,180);
    gGui1.Visible=true;
    SetGlobalInt(1, 1);
    gGui1.Clickable=true;
    gGui1.Transparency=30;
    waitforgui();
    Wait(2);
  }
}
  if ((GetGlobalInt(42)==2) && (mouse.IsButtonDown(eMouseRight))) {
    gGui1.Visible=false;
    guisetpos();
    resetglobals();
    SetGlobalInt(42, 1);
    mouse.SetBounds(0, 0, 0, 0);
}
}


Obviously the code is doing what I am telling it to do, I need a way to store the hotspot number and the call it when I right click without having to get the screen location(x,y)

The function above is called on the repeatdly_execute.... on every room
When clicking the button (look for example) I use this:
if ((Hotspot.GetAtScreenXY(mouse.x, mouse.y) == hotspot[1]) && (cEgo.Room==9)) {  /////use cd rack room9

thank you.
Title: Re: Hotspot problems again (need to store data)
Post by: miguel on Mon 12/05/2008 10:15:23
sorry to bring this up but just in case nobody noticed it :=
Title: Re: Hotspot problems again (need to store data)
Post by: SSH on Mon 12/05/2008 12:00:16
Just set a global variable at the point the right-click occurs. You could store the hotspot in a Hotspot * or store the x and y of the mouse at that point. Then remember to refer to the stored and not the current values when you need to.
Title: Re: Hotspot problems again (need to store data)
Post by: miguel on Mon 12/05/2008 12:17:26
Ok, I was told to do that but I can't get it working

If I set GI(200,1) when the right click happens then I'll have the GI always set to 1, how can I check it?

do I have to use:

If egoroom==1 and hotspot(mousex,y)==1 {setGI 200,1}
if egorrom==1 and               "                ==2 {    "      "   2}
...

and then let's say I right click, I can have:
if GI200==1 then action for hotspot 1 will happen

Ok, it makes sense, not me I don't,
I'll check it and report
Thank you SSH