Error when attempting to change inventory item description property

Started by Dor Hajaj, Sat 07/07/2018 01:14:22

Previous topic - Next topic

Dor Hajaj

Hi,

Can you explain why the following does not work?
Code: ags

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.

Crimson Wizard

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.


Dor Hajaj

But description is not a custom property.
I have this inventory item:

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?

Snarky

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
iMoney.Name = final;


Note that this won't work in older versions of AGS, where the property was read-only.

Crimson Wizard

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.


SMF spam blocked by CleanTalk