Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: ShadowMan on Wed 27/01/2016 09:46:53

Title: Hovering over hotspots
Post by: ShadowMan on Wed 27/01/2016 09:46:53
Hi everyone,

I quite recently started learning AGS, and I have a simple question. I didn't understand how to use the "@OVERHOTSPOT@", code.


This my example code, and I want to change it because it freezes the screen. I checked the old topics, but I didn't fully understand how to implement the "@OVERHOTSPOT@". Any help would be appreciated.

Code (ags) Select
function hBookcase_MouseMove()
{

  Display ("Bookcase" );

}


Also I am having trouble implementing this similar code:

QuoteHotspot *h = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
    if (h != null)
       lHover.Text = h.Name;
    else
       lHover.Text = "";

Where do I exactly put this, and why my program is keep saying me that I can't assing a value to a global variable when I try to implement it?

Thanks.
Title: Re: Hovering over hotspots
Post by: Slasher on Wed 27/01/2016 09:53:51
One way is to use a label on a gui and enter the labels text property to: @overhotspot@ it will then display hotspots, objects etc  description text.

just make sure the label is of adequate size (length) to accommodate any of the descriptions.
Title: Re: Hovering over hotspots
Post by: Khris on Wed 27/01/2016 15:58:55
The basic idea is to put text on a GUI label.
The way to do this is to call labelName.Text = "some text";
The code you found uses the current hotspot's name, which is what we want, but: this command is a one-off deal. The label text changes to what's on the right side of the equal sign, at the time the statement is run by AGS, and that's it. This assignment does not magically extend into the future, so what we need to do is update the text by running the statement over and over again.

And whenever you need code to run constantly, you put it inside the repeatedly_execute function in the global script (GlobalScript.asc).
function repeatedly_execute()
{     
  // Put here anything you want to happen every game cycle, even when
  // the game is paused. This will not run when the game is blocked
  // inside a command like a blocking Walk()
 
  lHover.Text = Game.GetLocationName(mouse.x, mouse.y);
}


(The code you found is slightly flawed btw, because h will never be null. If the mouse is outside any hotspots, h will equal hotspot[0]. Plus it seems like whoever wrote it wasn't aware of Game.GetLocationName)

You got an error because you put the code directly in a script, outside any functions. While you can declare "Hotspot *h;" outside a function, trying to assign Hotspot.GetAtScreenXY(mouse.x, mouse.y) is what caused the error.

Any command you use in a game has to go inside the appropriate function, otherwise AGS wouldn't know when to run it.


TL;DR:
Since having a label like that is very common, you can skip adding the code and simply enter @OVERHOTSPOT@ as the label's text, right in the GUI editor.