Display character name on mouse over *SOLVED*

Started by The creature, Sun 21/03/2021 16:44:30

Previous topic - Next topic

The creature

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

// 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
  
  //*******
  // 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.

Laura Hunt

Looks like you should be using "ch" instead of "character" here:

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




Khris

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.

SMF spam blocked by CleanTalk