More infos about : Items

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Shin
Posts: 7
Joined: Wed Jun 01, 2016 9:36 am

More infos about : Items

Post by Shin »

Hi !

I made some research on the documentation about the "Items" alternative to "Quests" and I didn't find anything that allow me to fully understand their purpose.

I thought I could use this to check if my player did collect a particular item relative to a quest and just check this condition like :
Items["my_item"].Is_Collected == true

But I guess that it's not been made that way because the only conditions I found is "Is_Item/Name/etc" but not something like Is_Possessed or something approaching.

Can someone help me to understand the purpose of this feature or at least tell me if this kind of info can be found on the documentation or any sample project or even video tutorial I don't know ^^

Thank you in advance :)
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: More infos about : Items

Post by Tony Li »

The Item table just holds data. It doesn't do anything with the data. You can define your own fields such as "Is Collected" or "Weight" or "Cost" and use them however you want. For example, if an NPC gives the player a Banana during a conversation, you could set the dialogue entry's Script field:
  • Dialogue Text: "Here, take this banana."
  • Script: Item["Banana"].Is_Collected = true
The exception is if the item has a field named "Is Item" that is False. This indicates that the item is actually a quest definition. The Dialogue System has special handling for quest definitions, such as showing them in the quest log window and quest tracker HUD. The table name "Quest" is an alias for "Item". You can use them interchangeably. So this:

Code: Select all

Item["Escape_Prison"].State = "active"
is the same as this:

Code: Select all

Quest["Escape_Prison"].State = "active"
Quests and items share the Item table because the Dialogue System's data structure is based on Chat Mapper. Rather than make up a data structure from scratch, the Dialogue System adopted Chat Mapper's data structure, which had already been refined and proven in many commercial games and other applications for years. However, Chat Mapper doesn't define a data structure for quests. In order to make quest editing accessible in Chat Mapper's interface, quests share the Item table.

When working with items, it's up to you to manage the values in the Item table. You can work with the Item table by putting Lua statements in the Script and Conditions fields of conversations. Or you can set values in your own scripts using the DialogueLua class. For example, if you have a pickup script on your Banana GameObject in the game, you could use this code:

Code: Select all

DialogueLua.SetItemField("Banana", "Is_Collected", true); 
If you're working with items and inventory in your game world, you may instead prefer to use an inventory management asset from the Asset Store, such as S-Inventory or Inventory Pro. The Dialogue System comes with S-Inventory Support and Inventory Pro Support. They provide additional functionality so you don't have to manage the Item table yourself.
Shin
Posts: 7
Joined: Wed Jun 01, 2016 9:36 am

Re: More infos about : Items

Post by Shin »

Thank you very much for this very detailed answer Tony !

Maybe you could even add it as is in the documentation to get a page describing Items and how to use them? (If there is not)

I didn't see that we could add custom fields on quests and items and it'll be useful. I'll add a Is_Collected field as you said :)

I've seen in the Quest example that we can add subtasks to a quest. Do you think I can make these subtasks be items to link the items we have to get in the quest with the quest itself?

Thank you again for your answer, the support you provide on DS is priceless!
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: More infos about : Items

Post by Tony Li »

Hi,

Good idea; I'll add this to the Item section in the manual.
Shin wrote:I've seen in the Quest example that we can add subtasks to a quest. Do you think I can make these subtasks be items to link the items we have to get in the quest with the quest itself?
Quest entries (subtasks) can't be items, but their text can reference fields in other items.

For example, say you have a quest entry to collect 3 bananas. You can define an item named "Banana" with a Number field named "Count". When the player picks up a banana in the game, increment the count:

Code: Select all

var currentCount = DialogueLua.GetItemField("Banana", "Count").AsInt;
DialogueLua.SetItemField("Banana", "Count", currentCount + 1); 
In your quest entry, you can set the text to include the current count by using the [lua] markup tag:
  • Name: "Gather Bananas"
  • Description: "Find three bananas."
  • Entry 1: "[lua( Item["Banana"].Count )] / 3 collected"
In the quest tracker HUD, it will look like this:

Gather Bananas
1 / 3 collected


To automatically update the quest tracker HUD after making a change to Dialogue System data, you'll also want to call DialogueManager.SendUpdateTracker(). So your code would change to:

Code: Select all

var currentCount = DialogueLua.GetItemField("Banana", "Count").AsInt;
DialogueLua.SetItemField("Banana", "Count", currentCount + 1);
DialogueManager.SendUpdateTracker(); 
Shin
Posts: 7
Joined: Wed Jun 01, 2016 9:36 am

Re: More infos about : Items

Post by Shin »

Amazing!

Thank you very very much! The "Banana" example fits perfectly my needs.

I'm not yet really familiar with Lua and its interactions with C# but the system seems really flexible so I can't wait to discover every possibilities the Dialogue System gives me :mrgreen:
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: More infos about : Items

Post by Tony Li »

Happy to help!

I can't resist providing one more bit of information. You can expose your own C# methods to Lua (see Register Functions). This is what the S-Inventory and Inventory Pro integrations do. For example, with S-Inventory you can set the Conditions field to this:
  • Conditions: GetItemAmount("Player", "Banana") >= 3
  • Dialogue Text: "Here are the 3 bananas I collected."
Post Reply