Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Dor Hajaj on Sat 07/07/2018 01:14:22

Title: Error when attempting to change inventory item description property
Post by: Dor Hajaj on Sat 07/07/2018 01:14:22
Hi,

Can you explain why the following does not work?
Code (ags) Select

iMoney.SetTextProperty("Description", final);

I'm getting an error stating that there is no such property in the schema.
I've looked at the manual, and the function is used in the same way.
Thank you.
Title: Re: Error when attempting to change inventory item description property
Post by: Crimson Wizard on Sat 07/07/2018 01:17:03
Quote from: Dor Hajaj on Sat 07/07/2018 01:14:22
I'm getting an error stating that there is no such property in the schema.

Before you can use properties in the script, you need to register them in the schema.

Related article: http://www.adventuregamestudio.co.uk/manual/ags20.htm#topic31
Quote
You'll notice that characters, objects, hotspots, rooms and inventory items all have a "Properties" option in their property grids. Select it and click the "..." button.

Since you don't yet have any custom properties, you'll get a blank window, so click the "Edit Schema" button. This takes you to the Schema Editor, where you can create the various properties you want in your game.

Title: Re: Error when attempting to change inventory item description property
Post by: Dor Hajaj on Sat 07/07/2018 07:41:39
But description is not a custom property.
I have this inventory item:
(https://i.imgur.com/5ZJgQyP.png)
I would like to change the description on at times through the code.
The manual states:
Quote
SetTextProperty (inventory)
bool InventoryItem.SetTextProperty(const string property, const string value)

Sets the new value text for the custom property for the specified inventory item. Returns TRUE if such property exists and FALSE on failure.
This command works with Text properties only. The property's text will be changed to new value.

Use the equivalent SetProperty function to set a non-text property.

Example:

iKey.SetTextProperty("Description", "A rusty key");

will change key's "description" property.
Compatibility: Supported by AGS 3.4.0 and later versions.

See Also: InventoryItem.SetProperty

So it's just a coincidence that the 'Description' property is stated there? this property value is inaccessible in run time?
Title: Re: Error when attempting to change inventory item description property
Post by: Snarky on Sat 07/07/2018 08:43:46
It's a little confusing:

Yes, the fact that the custom property is called "Description" is just a coincidence, and probably a poor choice of an example.

The property that is called "Description" in the editor corresponds to the InventoryItem.Name property in scripts. The property that is called "Name" in the editor, on the other hand, is not accessible from scripts (it determines the variable name of the inventory item). So to do what you are trying, you should put:

Code (ags) Select
iMoney.Name = final;

Note that this won't work in older versions of AGS, where the property was read-only.
Title: Re: Error when attempting to change inventory item description property
Post by: Crimson Wizard on Sat 07/07/2018 12:30:37
Right, the functions SetProperty/SetTextProperty/GetProperty/GetTextProperty are working only with Custom Properties from the custom schema.
Regular properties are accessed directly, like Snarky showed above.
Title: Re: Error when attempting to change inventory item description property
Post by: Dor Hajaj on Sat 07/07/2018 15:24:00
Thank you!