Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: The creature on Sun 21/03/2021 16:44:30

Title: Display character name on mouse over *SOLVED*
Post by: The creature on Sun 21/03/2021 16:44:30
Hi Everyone

I know this is an issue that has come up time and time again but for the life of me I cant find anything about this problem (although I'm sure I have seen posts about this in the past). But I'm trying to display character names in a GUI on mouse over. I need to display a custom text property though as I need to change some character names at runtime.

my script is as follows:
 
Code (ags) Select

// Display character names.
  Character *ch = Character.GetAtScreenXY(mouse.x, mouse.y);
  if (ch != null)
  {
    String npcName = character.GetTextProperty("NPC Name");
    gDetailsBox.Visible=true;
    lPointerOver.Text=String.Format("%s", npcName);
  }


At the moment it gives me a compile error saying it's requiring a [  doesn't make a lot of sense to me. I just cant seem to figure it out although on paper it should be pretty simple. Does anyone have any thoughts?

The help would be appreciated as it's really bugged me for a long time.

The C



*************
** Update
*************

I am very sorry, I figured it out but here is my code for future ref:

Code (ags) Select
 
  //*******
  // Display character names.
  Character *ch = Character.GetAtScreenXY(mouse.x, mouse.y);
  if (ch != null)
  {
    String npcName;
    if (ch) npcName = ch.GetTextProperty("NPC Name");
    gDetailsBox.Visible=true;
    lPointerOver.Text=String.Format("%s", npcName);
  }


again, very sorry.
Title: Re: Display character name on mouse over
Post by: Laura Hunt on Sun 21/03/2021 16:57:25
Looks like you should be using "ch" instead of "character" here:

Code (ags) Select
String npcName = ch.GetTextProperty("NPC Name");


Title: Re: Display character name on mouse over *SOLVED*
Post by: Khris on Mon 22/03/2021 13:26:17
To clarify the error message: there's a global array called  character  and you'd use something like  character[0]  to access the first Character. That's why AGS is expecting a square bracket.