Page 1 of 1

Read data form item database

Posted: Thu Feb 07, 2019 2:09 pm
by harshad.asawale
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!

Re: Read data form item database

Posted: Thu Feb 07, 2019 2:46 pm
by Tony Li
Hi,

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"));
    }
}
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:

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);
    }
}