Random Node?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
alfonso
Posts: 104
Joined: Mon Jul 13, 2015 6:31 am

Random Node?

Post by alfonso »

Hi tony!

i would like to make a npc says a random node each time i talk with him, for this in the start node in the script i put this code

Code: Select all

Conversation[21].Count = RandomElement("0|1|2")
Note: Count is a number variable that each conversation has, is a counter to know how many times the player talks to that npc.

in each child of start has a condition like this with the correct number

Code: Select all

Conversation[21].Count == 0
but not seem to work, dont know if for the returned string of RandomElement and the count is a number value

Any idea? thanks :)
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Random Node?

Post by Tony Li »

Hi Alfonso,

Two things:

1. If you want a number instead of a string, you can use Lua's math.random function:

Code: Select all

Conversation[21].Count = math.random(0,2)
2. The Dialogue System evaluates all child conditions before playing the start node. It has to do this to know whether the next stage in the conversation is another subtitle or a response menu, since the continue button can be configured to do different things based on this.

If you're going to set a value in the start node's Script, add an empty node between the start node and the real child nodes:
  • START - Script: Conversation[21].Count = math.random(0,2)
    • Empty - Sequence: None()
      • Child1 - Conditions: Conversation[21].Count == 0
      • Child2 - Conditions: Conversation[21].Count == 1
      • Child3 - Conditions: Conversation[21].Count == 2
This delays the evaluation of Conversation[21].Count == ??? until after the start node has run.
alfonso
Posts: 104
Joined: Mon Jul 13, 2015 6:31 am

Re: Random Node?

Post by alfonso »

thanks i have no idea that lua has math.random where can i check the lua method i can use?

in the other hand, works perfect as always when you help me :)
but i didnt need the delay node, dont know why but in the start works all fine.
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Random Node?

Post by Tony Li »

LuaInterpreter (the default version of Lua that the Dialogue System uses) implements most of the standard Lua functions. You can read more about Lua 5.1 functions in the Lua documentation. This is the main documentation link, which has links to documentation in Spanish, English, and other languages.
Post Reply