Read data form item database

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
harshad.asawale
Posts: 12
Joined: Wed Jan 30, 2019 1:02 pm

Read data form item database

Post 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!
User avatar
Tony Li
Posts: 22056
Joined: Thu Jul 18, 2013 1:27 pm

Re: Read data form item database

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