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

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
OddMan2
Posts: 29
Joined: Fri Feb 11, 2022 11:14 am

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

Post 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")
				[ . . . ]
           	
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

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

Post 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
OddMan2
Posts: 29
Joined: Fri Feb 11, 2022 11:14 am

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

Post by OddMan2 »

Thank you very much tony, your responses are always fast and on point.
I updated my code and it works!
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

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

Post by Tony Li »

Glad to help!
Post Reply