- Home /
Dialog trees with conditions
Hello,
I am creating the dialog system for my RPG game.
The idea is that the possible interactions the player will be able to choose from will depend on different factors, namely, the NPC's "type" (peasant, warrior...) and sometimes one or more attributes (stats of the character, relationship to the NPC...). In a way it's similar to the dialog system from Fallout.
The dialog lines the player will be able to choose from are gonna be stored in XML which will have a similar structure to this:
<interaction id="1">
<characterType>peasant</charactertype>
<precondition>
<type>self<type>
<attribute>intelligence</attribute>
<value>5</attribute>
</precondition>
<text>I know the answer</text>
...
</interaction>
<interaction id="2">
<characterType>peasant</charactertype>
<precondition>
<type>other<type>
<attribute>Relationship</attribute>
<value>30</attribute>
</precondition>
<text>Can you do me a favor?</text>
...
</interaction>
My problem comes when I try to translate this conditions into Unity variable comparisons. From what I have been reading it seems that a dictionary is the typical option but, since I want to have the flexibility to compare with almost any variable from the character or NPC, I'm not sure if this is an option for me and maybe a string comparison with the variable name would be better (although this seems very obscure and dangerous and any change in a variable's name could break the game).
So my question(s) is: Is it possible to use a dictionary for this? Or maybe there is an alternative way that would be better for my case?
Thank you
Your answer
![](https://koobas.hobune.stream/wayback/20220612103519im_/https://answers.unity.com/themes/thub/images/avi.jpg)