[SOLVED] Floaty label to follow cursor...

Started by Technocrat, Tue 21/04/2015 17:27:00

Previous topic - Next topic

Technocrat

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

    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)?

Crimson Wizard

#1
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

	// 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);
		}
	}

Technocrat

Aahh, perfect - that's sorted it out. Many thanks!


SMF spam blocked by CleanTalk