GetTextProperty problem

Started by pixelincognito, Mon 23/10/2017 10:48:38

Previous topic - Next topic

pixelincognito

Hi

I'm having a slight issue, I have a label which I use to to tell the player the name of objects/hotspots the mouse rolls over.
I'm working on a combat system where I'm using objects as enemies and I've set an 'Enemy Name' as a custom schema property.

Trying to keep things simple I have this in my repeatedly_execute_always()

Code: ags

int Local = GetLocationType(mouse.x, mouse.y);
  
    if (Local==eLocationObject){ //Displays Objects in the Mouse-over Text
      
      String Enemy_Name = object[0].GetTextProperty("Enemy Name");
      String Enemy_Name2 = object[1].GetTextProperty("Enemy Name");
      lFocus.Text=String.Format("%s", Enemy_Name);
      lFocus.Text=String.Format("%s", Enemy_Name2);
    }


This kind of works but it's only displaying the name of the second object and the first object's name is being overwritten by the second. E.i I have 2 bats in  room, the first bat is called "Bat" the second is called "BatFACE" and with the code above both are being labeled as "BatFACE"

Any help would be greatly appreciated as I'm a little stuck, this is the first time I've really used custom properties and the schema.

Cheers.

Khris

The issue you have has nothing to do with properties / schemas. Your line 7 is immediately obliterated by line 8, since you're overwriting the label text you just set. What you want is find out the object currently under the mouse, and use that.

Code: ags
Object* o = Object.GetAtScreenXY(mouse.x, mouse.y);
if (o != null) lFocus.Text = o.GetTextProperty("Enemy Name");


Also, just in case you don't know: objects already support a Name you can enter in the properties.
To use that in-game, just do lFocus.Text = o.Name;

pixelincognito

That worked a charm, thank you Khris, you're a star.

Cheers

SMF spam blocked by CleanTalk