Selecting nodes in a conversation randomly
Selecting nodes in a conversation randomly
Hi ,
I have a set of dialogues that should play randomly if player chooses to talk to a particular NPC.
For eg assuming NPC Tom has conversation with dialogues 1,2,3 ; if player chooses to speak with Tom then sometimes Tom will start with dialogue 1 , 2 or 3 randomly. I can make different conversations all together and let the script trigger any of them based on Random.value but am looking for something in DialogueSystem that you do the same with nodes
Thanks.
Nishant
I have a set of dialogues that should play randomly if player chooses to talk to a particular NPC.
For eg assuming NPC Tom has conversation with dialogues 1,2,3 ; if player chooses to speak with Tom then sometimes Tom will start with dialogue 1 , 2 or 3 randomly. I can make different conversations all together and let the script trigger any of them based on Random.value but am looking for something in DialogueSystem that you do the same with nodes
Thanks.
Nishant
Re: Selecting nodes in a conversation randomly
Hi Nishant,
In the START node, set the Script field to:
Then create an empty child node. Set its Sequence to:
Then create three child nodes of that node. Set their Conditions fields to:
et cetera for 2 and 3.
Your conversation will be structured like this:
Another way is to use the Dialogue System's RandomElement() Lua function:
In the START node, set the Script field to:
Code: Select all
randomValue = math.random(3)
Code: Select all
None()
Code: Select all
randomValue == 1
Your conversation will be structured like this:
- [0] START - Script: randomValue=math.random(3)
- [1] Sequence: None()
- [2] Dialogue Text: "This is dialogue 1" - Conditions: randomValue==1
- [3] Dialogue Text: "This is dialogue 2" - Conditions: randomValue==2
- [4] Dialogue Text: "This is dialogue 3" - Conditions: randomValue==3
Another way is to use the Dialogue System's RandomElement() Lua function:
- [0] START - Script: randomValue=math.random(3)
- [1] Dialogue Text: [lua(RandomElement("Hello|Hi|What's up?"))]
Re: Selecting nodes in a conversation randomly
Perfect ... that solves it
Thanks
Thanks
Re: Selecting nodes in a conversation randomly
Someone had a question about the math.random(#) method described above. In his case, sometimes the Dialogue System wouldn't match any of the nodes' conditions, so it would end the conversation.
One possible cause is that the random value function:
randomValue = math.random(3)
generates a number that's higher than the number of responses.
One solution is to make sure randomValue is always set to a range that's covered by all the conditions. For example, math.random(3) will return a number 1, 2, or 3. So your follow-up nodes should have conditions "randomValue == 1" through "randomValue == 3".
The other solution, which avoids user error in the conditions, is to add a guaranteed fallback node. The conversation will use this node if none of the other nodes' conditions are true. To set up the fallback node, create an additional follow-up node with no conditions. Then click on the link arrow that leads to that node. In the Inspector, change the Priority dropdown to BelowNormal. So the conversation will be structured like this:
One possible cause is that the random value function:
randomValue = math.random(3)
generates a number that's higher than the number of responses.
One solution is to make sure randomValue is always set to a range that's covered by all the conditions. For example, math.random(3) will return a number 1, 2, or 3. So your follow-up nodes should have conditions "randomValue == 1" through "randomValue == 3".
The other solution, which avoids user error in the conditions, is to add a guaranteed fallback node. The conversation will use this node if none of the other nodes' conditions are true. To set up the fallback node, create an additional follow-up node with no conditions. Then click on the link arrow that leads to that node. In the Inspector, change the Priority dropdown to BelowNormal. So the conversation will be structured like this:
- [0] START - Script: randomValue=math.random(3)
- [1] Sequence: None()
- [2] Dialogue Text: "This is dialogue 1" - Conditions: randomValue==1
- [3] Dialogue Text: "This is dialogue 2" - Conditions: randomValue==2
- [4] Dialogue Text: "This is dialogue 3" - Conditions: randomValue==3
- [5] Dialogue Text: "This is guaranteed fallback dialogue." (No Conditions. Priority=BelowNormal)
- [1] Sequence: None()
Re: Selecting nodes in a conversation randomly
Is there a way to set different percentage chances for each possible node?
For example, I have two possible dialogue outcomes, but I want one to have an 80% chance and the other 20% chance.
For example, I have two possible dialogue outcomes, but I want one to have an 80% chance and the other 20% chance.
Re: Selecting nodes in a conversation randomly
You can do the same as above. Set a random value -- for example 1-100. Then branch based on that value:
- [0] START - Script: randomValue=math.random(100)
- [1] Sequence: None()
- [2] Dialogue Text: "This line has a 20% chance to appear." - Conditions: randomValue > 80
- [3] Dialogue Text: "This line has an 80% chance to appear."
- [1] Sequence: None()
Re: Selecting nodes in a conversation randomly
Perfect, thank you!
Re: Selecting nodes in a conversation randomly
Happy to help!