Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Sensei on Thu 12/04/2012 11:19:00

Title: How to show name of Hotspot, Object, Char etc.
Post by: Sensei on Thu 12/04/2012 11:19:00
It must by something incredibly basic or incredibly complex. I couldn´t find solution trough entire forum. :)

Basicly... I want to show name of Hotspot, Object, Character and Inventory item when mouse scroll over it. The text should be locked on side of cursor and should dissapear when mouse leave current object.
This feature should give player feedback that he is just pointing on sometnhing interactive and not just background. I´ve seen it in many games and i would like to have this feature in my own.

So i ask.
Is there any way to do it? I was looking for some Module but unsuccesfuly.
If you are willing to share your own solution, i would be eternaly grateful.

Thanks ;)
Title: Re: How to show name of Hotspot, Object, Char etc.
Post by: steptoe on Thu 12/04/2012 11:28:38
Nearest Iv'e seen is FloatingHotspot in the modules/plugins quite a while back..

Similar to Overhotspots feature of AGS but descriptions show near mouse cursor.


Title: Re: How to show name of Hotspot, Object, Char etc.
Post by: Khris on Thu 12/04/2012 23:48:58
There are lots of threads about this already since that question gets posted about once per month.

Basically, create a small GUI (~ 100 x 10 pixels, visibility: Normal, on) with border and background color 0 (= transparent) and put a label on it.

To have it always next to the cursor, reposition it in the Globalscript.asc's repeatedly_execute function. If you called the GUI gLocationName, the code should be:

  int x = mouse.x + 3;
  int y = mouse.y + 5;
  InventoryItem*ii = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
  Label*lbl = gLocationName.Controls[0].AsLabel;
  String text;
  if (ii) text = ii.Name;
  else text = Game.GetLocationName(mouse.x, mouse.y);
  if (x > 250) x = (x - 6) - GetTextWidth(text, lbl.Font);
  gLocationName.SetPosition(x, y);


(There's also the @OVERHOTSPOT@ token which if put as text of the label will always show the name, too, but afaik this doesn't work for inv items.)
Title: Re: How to show name of Hotspot, Object, Char etc.
Post by: Lewis on Fri 13/04/2012 17:50:35
Quote from: Khris on Thu 12/04/2012 23:48:58
(There's also the @OVERHOTSPOT@ token which if put as text of the label will always show the name, too, but afaik this doesn't work for inv items.)

Pretty sure it does, in fact.
Title: Re: How to show name of Hotspot, Object, Char etc.
Post by: monkey0506 on Fri 13/04/2012 18:18:01
@OVERHOTSPOT@ will display the name of whatever the mouse is over (including inventory items), but (I'm pretty sure) you can't customize the text with cursor-based verbiage (e.g., "Walk to Roger"). It definitely doesn't allow you to easily replace the name of the item the mouse is over dynamically, for example if you have a custom variable to store changed hotspot names (since Hotspot.Name can't be changed at run-time).

This would be a good area for improvement. In fact, if you could assign a translateable string to each mouse cursor and then set a label to something like "@MODETEXT@ @MOUSEOVER@" it would save a lot of trouble for the end-user (especially the newbie!).
Title: Re: How to show name of Hotspot, Object, Char etc.
Post by: Sensei on Mon 16/04/2012 11:06:29
Thanks guys. Works fine.

Yet there is one problem.
When i scroll mouse over lower edge of screen, the game crushes. It writes: "GUI.Y: co-ordinates specified are ou t of range."

I´m not experienced enough to fix this bug myself. Can you help me with that?
Title: Re: How to show name of Hotspot, Object, Char etc.
Post by: Khris on Mon 16/04/2012 11:28:57
If you're using my code, put this above the last line:

  if (y > System.ViewportHeight) y = mouse.y - 5;
Title: Re: How to show name of Hotspot, Object, Char etc.
Post by: Sensei on Wed 25/04/2012 14:14:52
Thanks Khris. It helps a little but not entirely.
It´s interesting. Sometimes when i scroll lower edge it works just fine. No error at all. But sometimes it crash anyway. I tried to find why is that but i didn´t found legality... ???
Title: Re: How to show name of Hotspot, Object, Char etc.
Post by: Khris on Wed 25/04/2012 14:39:13
You can change the check before the .SetPosition command, for instance:

  y = mouse.y - 5;
  int y_limit = System.ViewportHeight - 10;
  if (y > y_limit) y = y_limit;
Title: Re: How to show name of Hotspot, Object, Char etc.
Post by: Sensei on Wed 25/04/2012 16:06:30
You are miracle Khris. :) Problem solved
Title: Re: How to show name of Hotspot, Object, Char etc.
Post by: zeta_san on Sat 30/12/2023 19:49:23
Quote from: Khris on Thu 12/04/2012 23:48:58There are lots of threads about this already since that question gets posted about once per month.

Basically, create a small GUI (~ 100 x 10 pixels, visibility: Normal, on) with border and background color 0 (= transparent) and put a label on it.

To have it always next to the cursor, reposition it in the Globalscript.asc's repeatedly_execute function. If you called the GUI gLocationName, the code should be:

  int x = mouse.x + 3;
  int y = mouse.y + 5;
  InventoryItem*ii = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
  Label*lbl = gLocationName.Controls[0].AsLabel;
  String text;
  if (ii) text = ii.Name;
  else text = Game.GetLocationName(mouse.x, mouse.y);
  if (x > 250) x = (x - 6) - GetTextWidth(text, lbl.Font);
  gLocationName.SetPosition(x, y);

(There's also the @OVERHOTSPOT@ token which if put as text of the label will always show the name, too, but afaik this doesn't work for inv items.)


hi, I tried to insert this into my Tumbleweed style code, but it doesn't work.. it gives me error
Title: Re: How to show name of Hotspot, Object, Char etc.
Post by: Crimson Wizard on Sat 30/12/2023 22:19:56
Quote from: zeta_san on Sat 30/12/2023 19:49:23hi, I tried to insert this into my Tumbleweed style code, but it doesn't work.. it gives me error

Hello. Please always post the relevant piece of code and tell what the error message is. It's difficult to answer questions without knowing that.
Title: Re: How to show name of Hotspot, Object, Char etc.
Post by: Khris on Sun 31/12/2023 12:13:46
That code needs to go inside the repeatedly_execute function, you cannot paste it directly into a script.
It also requires the existence of a GUI called gLocationName that has a label as its first control (i.e. the ID is 0)
Title: Re: How to show name of Hotspot, Object, Char etc.
Post by: zeta_san on Sun 31/12/2023 17:25:32
sorry @Crimson Wizard you're right


@Khris
I placed the code in the repeatedly_execute function in globalscript.asc
I made the GUI called gLocationName with a label as you described.

The mistake is
Local variable cannot have the same name as an import