Page 1 of 1

Correct way to set an item custom field value via LUA?

Posted: Thu Feb 24, 2022 3:42 pm
by OddMan2
Hello,
i am trying to update a custom field i created on items:

Code: Select all

Item["Letter"].InInventory = true
  • the field is a Bool, called "InInventory"
  • the code is in a script field during a normal conversation
  • The debug log says the script is being executed "Dialogue System: Lua(Item["Letter"].InInventory = true)"
The value in the database never changes, what am i doing wrong?

to add more information:
i use this "InInventory" field to check if the item is in the player's inventory.

Code: Select all

	foreach (var item in DialogueManager.masterDatabase.items)
		{
			if (item.IsItem)
			{  
				if (item.AssignedField("InInventory").value == "True")
				[ . . . ]
           	

Re: Correct way to set an item custom field value via LUA?

Posted: Thu Feb 24, 2022 4:01 pm
by Tony Li
Hi,

The database is read-only at design time. Changes occur in the Lua environment. If you're playing in the Unity editor, you can watch the changes in the Dialogue Editor's Watches tab.

To check the value in C# code:

Code: Select all

if (DialogueLua.GetItemField("Letter", "InInventory").asBool) { ... }
To check it in Lua, such as in a dialogue entry node's Conditions field:
  • Conditions: Item["Letter"].InInventory == true

Re: Correct way to set an item custom field value via LUA?

Posted: Thu Feb 24, 2022 4:27 pm
by OddMan2
Thank you very much tony, your responses are always fast and on point.
I updated my code and it works!

Re: Correct way to set an item custom field value via LUA?

Posted: Thu Feb 24, 2022 4:34 pm
by Tony Li
Glad to help!