SetTextProperty won't recognise "description"

Started by bauldur_rises, Sat 05/01/2019 11:37:45

Previous topic - Next topic

bauldur_rises

Hi guys, I'm having a problem. I'd like to change the description of an object at a particular time, and so I've been using this line of script:

Code: ags

oObjectName.SetTextProperty("description", "New Description");


But when I test it in game, the game crashes with this error message:

"Get Property: no such property found in schema. Make sure you are using the property's name, and not its description, when calling this command."

I've experimented with capitalising 'description' and trying it without the speech marks, just in case.

Am I missing something key? Thanks for your help.

Crimson Wizard

#1
These functions only work with custom properties, the ones that you created in a properties schema in the editor.

The builtin properties, like description, are accessible directly. Not all of them may be changed though (which sometimes does not make sense). In case of object's description the corresponding property is oObjectName.Name, but it's read-only.

bauldur_rises

So is there no way to alter an object's description?

Matti

You can manually change the object's description using a variable. If you have a hotspot label like this:

Code: ags

l_Hotspots.Text = Game.GetLocationName(mouse.x, mouse.y)


.. and e.g. object "table" needs to be changed, because it's broken, you can do something like this, using a bool "table_broken":

Code: ags

if (l_Hotspots.Text == table.Name && table_broken == true) l_Hotspots.Text = "broken table";

Crimson Wizard

#4
Actually you can just create your own custom property and use that in the same way that you wanted to use description earlier.

The difference would be that -
1) You would have to type object descriptions in custom property rather than standard Description field. OR, alternatively, you may write a script that copies value from Description to your property at game start and room enter.
2) you cannot use automatic replacement with "@OVERHOTSPOT@" string in label, you would have to manually get the property value and assign it to the label text or anywhere where you want this description to appear.


EDIT

To expand my answer further, here's the example of how the object's Description could be copied into properties on every first room load:
Code: ags

// In GlobalScript.asc
function on_event (EventType event, int data) 
{
    if (event == eEventEnterRoomBeforeFadein)
    {
         String doonce = String.Format("RoomStartup%d", player.Room);
         if (Game.DoOnceOnly( doonce )) // make sure it happens only once per room
         {
              for (int i = 0; i < MAX_OBJECTS; i++)
              {
                   // this sets value of the custom property "Description" to be equal to object's description you typed in the editor
                   object[i].SetTextProperty("Description", object[i].Name);
              }
         }
    }
}

bauldur_rises

Thank you for the replies!

Crimson Wizard, thank you so much for your advice!  I'm still very new to scripting, and what you provided has pushed me a great deal!

What I'm trying to understand now is how to then make the custom Description property from the object over which the mouse is hovering appear in the 'Action Text' bar at the bottom of the screen a la Lucas Arts games.

Code: ags

	if (player.ActiveInventory == null)
	 {
          if (GetLocationType = eLocationObject)
               {
          lblActionText.Text = ??????????
                }
      else
            {
        lblActionText.Text = Game.GetLocationName(mouse.x, mouse.y);
            }
	}

Crimson Wizard

#6
Right, so, for almost every type of thing in AGS there is a GetAtScreenXY function which lets you find if there's a thing of that type at the given screen coordinates:

Code: ags

int loctype = GetLocationType(mouse.x, mouse.y);
if (loctype == eLocationObject)
{
     Object *o = Object.GetAtScreenXY(mouse.x, mouse.y);
     lblActionText.Text = o.GetTextProperty("Description");
}



SMF spam blocked by CleanTalk