Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Technocrat on Tue 21/04/2015 17:27:00

Title: [SOLVED] Floaty label to follow cursor...
Post by: Technocrat on Tue 21/04/2015 17:27:00
So, as you might have guessed, I'm engineering a floating label to follow the cursor around. To prevent the text running off the edge of the screen, I started to cobble up this script:

Code (AGS) Select

    gHovertext.X=mouse.x-600;
    String lblTxt = LabelHoverText.Text;
    int TxWidth = lblTxt.Length*10;
   
    if(gHovertext.X<(lblTxt.Length*10)-600)gHovertext.X=-600+TxWidth;
   

    gHovertext.Y=mouse.y-20;


...so, the plan is that, as the length of the text in the label gets longer, the GUI's x is pushed over to the right by ten pixels per letter.

HOWEVER, I noticed that every single time, it was coming up as 13 characters long, no matter the actual length of the text. This is when I realised that it was going by @OVERHOTSPOT@, which has 13 characters!

Is there some way to get the text produced by this (or the length of the string, at least)?
Title: Re: Floaty label to follow cursor...
Post by: Crimson Wizard on Tue 21/04/2015 18:49:47
You would have to use Game.GetLocationName(x, y) instead:
http://www.adventuregamestudio.co.uk/wiki/Game_/_Global_functions#Game.GetLocationName


I would also like to point you to the very simple and easy to expand BASS template, that has this functionality included:
http://www.adventuregamestudio.co.uk/forums/index.php?topic=48441.0

E: ouch, it appears it does not have this label floating after the mouse, but keeps it at the bottom.

Anyway, here's a sample script from BASS, just for reference:
Code (ags) Select

// Action Text
// We always display the name of what is under the mouse, with one exception:
// IF the player has an inventory item selected and hovers over the same inventory item,
// we display nothing to indicate that an item can not be used on itself
if (player.ActiveInventory == null)
{
lblActionText.Text = Game.GetLocationName(mouse.x, mouse.y);
}
else
{
InventoryItem *i = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
if (i != null && (i.ID == player.ActiveInventory.ID))
{
lblActionText.Text = "";
}
else
{
lblActionText.Text = Game.GetLocationName(mouse.x, mouse.y);
}
}
Title: Re: Floaty label to follow cursor...
Post by: Technocrat on Tue 21/04/2015 22:39:43
Aahh, perfect - that's sorted it out. Many thanks!
Title: Re: [SOLVED] Floaty label to follow cursor...
Post by: Calin Leafshade on Fri 24/04/2015 10:17:29
I made a module for that!

http://www.adventuregamestudio.co.uk/forums/index.php?topic=49970.0