Condition (Result) Change in the Same(Repeated) Conversation

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Twig Yu
Posts: 2
Joined: Mon May 09, 2022 8:25 am

Condition (Result) Change in the Same(Repeated) Conversation

Post by Twig Yu »

Don't know how to "RESET" the Result my Conditions.
I've been trying create a Craft/Merchant(Shop) function. by using this DialogueSystem
For example, I set a npc named "Bonfire" and whenever the player run into it he will trigger the Conversation which has 3 nodes: "Get warmed" , "Roast some meat" and "You don't have: Raw Meat!".
I set a variable (number) ""RawMeat" and a Condition "RawMeat>=1" linked to that Roast node(by the "..."button).
It worked at the first time that the player run into the ""You don't..." node when I didn't get meat in my inventory and the variable"RawMeat" did shows "0" (in the Dialogue Editor page).
Conversely, when i get a meat first and the the variable did shows "1", then the player run into the "Roast.."node and I did get that roast through some of my C#s.
The problem is, when I triggered that Condition, it doesn't get updated(Changed): I run into the "You don't" node without the meat and soon I get a meat to interact with that "Bonfire" again(variable "RawMeat" shows "1"), but this time the "Bonfire" still said"You don't".
Same as the contrary(Restart the Game): I get a meat first then run into "Roast some" this time, the interesting thing is I can still trigger that "Roast" node even I don't get any meat at inventory(even the Variable has already been reduced to minus)
It seems that the condition result(true/false) it returned doesn't get changed actually, did I do something wrong?
How could I fix it?
User avatar
Tony Li
Posts: 22148
Joined: Thu Jul 18, 2013 1:27 pm

Re: Condition (Result) Change in the Same(Repeated) Conversation

Post by Tony Li »

You can use a Dialogue System variable, but instead of a variable I recommend reading directly from your inventory. The Dialogue System has integrations with several inventory systems such as Ultimate Inventory System and Inventory Engine as well as the inventory systems inside assets such as ORK Framework, Invector, etc. If you are using one of those systems, configure your conversation's Conditions to check the integration's Lua functions.

Otherwise, you can write your own C# methods and register them with Lua. (Tutorial)

If you are using a Dialogue System variable instead of a Lua function, use DialogueLua.SetVariable() to increment the variable in C#:

Code: Select all

DialogueLua.SetVariable("RawMeat", DialogueLua.GetVariable("RawMeat").asInt + 1);
or, if you run Lua code:

Code: Select all

Variable["RawMeat"] = Variable["RawMeat"] + 1
In either case, structure your conversation like this:

bonfire.png
bonfire.png (33.48 KiB) Viewed 437 times

When you restart the game, you should reset the Dialogue System's variables. If you are using the save system:

Code: Select all

PixelCrushers.SaveSystem.ResetGameState();
If you are not using the save system:

Code: Select all

DialogueManager.ResetDatabase();
Twig Yu
Posts: 2
Joined: Mon May 09, 2022 8:25 am

Re: Thanks!

Post by Twig Yu »

Great!It worked as I expected after I changed my "InitialFloatValue" to your "SetVariable" code in my C#(Guess I get it wrong about the "InitialFloatValue", even though it did changed the value showed on the DialogueEditor page, and it doesn't help in changing the actual values).Thank you Tony! You really made my day! :D
User avatar
Tony Li
Posts: 22148
Joined: Thu Jul 18, 2013 1:27 pm

Re: Condition (Result) Change in the Same(Repeated) Conversation

Post by Tony Li »

Glad to help!
Post Reply