Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: bauldur_rises on Sat 05/01/2019 11:37:45

Title: SetTextProperty won't recognise "description"
Post by: bauldur_rises on Sat 05/01/2019 11:37:45
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) Select

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.
Title: Re: SetTextProperty won't recognise "description"
Post by: Crimson Wizard on Sat 05/01/2019 11:50:43
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.
Title: Re: SetTextProperty won't recognise "description"
Post by: bauldur_rises on Sat 05/01/2019 11:56:43
So is there no way to alter an object's description?
Title: Re: SetTextProperty won't recognise "description"
Post by: Matti on Sat 05/01/2019 12:14:32
You can manually change the object's description using a variable. If you have a hotspot label like this:

Code (ags) Select

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

if (l_Hotspots.Text == table.Name && table_broken == true) l_Hotspots.Text = "broken table";
Title: Re: SetTextProperty won't recognise "description"
Post by: Crimson Wizard on Sat 05/01/2019 12:33:18
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) Select

// 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);
              }
         }
    }
}
Title: Re: SetTextProperty won't recognise "description"
Post by: bauldur_rises on Sun 06/01/2019 11:39:25
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) Select

if (player.ActiveInventory == null)
{
          if (GetLocationType = eLocationObject)
               {
          lblActionText.Text = ??????????
                }
      else
            {
        lblActionText.Text = Game.GetLocationName(mouse.x, mouse.y);
            }
}
Title: Re: SetTextProperty won't recognise "description"
Post by: Crimson Wizard on Sun 06/01/2019 12:21:24
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) Select

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

Title: Re: SetTextProperty won't recognise "description"
Post by: bauldur_rises on Sun 06/01/2019 22:24:09
That works, thank you for the help!