I am trying to populate inventory UI, based on the information present in the Item DB.
Currently, I can iterate thru the DB using the following code.
foreach (var item in DialogueManager.masterDatabase.items)
{
Debug.Log (item.id + " "+ item.Name );
}
I am unable to actually read the data associated with the individual item
For e.g. inventory (bool) , TotalNumber (int) , IsItem (bool) etc.
Please let me know how I can do this.
Thanks!
Read data form item database
Re: Read data form item database
Hi,
Those are in the item's fields. Use the Item.LookupXXX() functions:
The Name and IsItem properties are actually just shortcuts to LookupValue("Name") and LookupBool("IsItem").
Note that the data in the dialogue database is static. At runtime, the Dialogue System loads this data into Lua and makes changes there. So you may want to do this:
Those are in the item's fields. Use the Item.LookupXXX() functions:
Code: Select all
foreach (var item in DialogueManager.masterDatabase.items)
{
if (item.IsItem)
{
Debug.Log (item.id + " "+ item.Name);
Debug.Log ("inventory = " + item.LookupBool("inventory"));
Debug.Log ("TotalNumber = " + item.LookupInt("TotalNumber"));
}
}
Note that the data in the dialogue database is static. At runtime, the Dialogue System loads this data into Lua and makes changes there. So you may want to do this:
Code: Select all
foreach (var item in DialogueManager.masterDatabase.items)
{
if (item.IsItem)
{
Debug.Log (item.id + " "+ item.Name);
Debug.Log ("inventory = " + DialogueLua.GetItemField(item.Name, "inventory").asBool);
Debug.Log ("TotalNumber = " + DialogueLua.GetItemField(item.Name, "TotalNumber").asInt);
}
}