I’m trying to create a simple dialogue tree using ‘Nodes’ which can be a ‘Dialogue’ or ‘Conditional’ node. Which have inputs and outputs which point to other ‘Nodes’. To create a flow/conditional route for the dialogue.
However i’m struggling with my declarations. In that a node needs to know the contents of another node before i’ve declared it?
For e.g. my conditionNotMet is referencing an incorrect ‘conditionalNode’
Interested in knowing the best kind of practice for this implementation type.
Cheers
My start function is below, so you can see what I mean (realise it’s a bit messy and nonsensical at the moment. Will be adding tidy constructors and such later on)
void Start()
{
conditionNotMet = new Dialogue ("Char1", "Oh, you haven't met the condition yet.");
conditionNotMet.pointer01 = conditionalNode;
conditionNotMet.isDirect = false;
conditionNotMet.inputNode = conditionalNode;
conditionMet = new Dialogue ("Char1", "Oh, you met the condition?");
conditionMet.inputNode = conditionalNode;
conditionalNode = new Conditional ();
conditionalNode.isConditionMet = false;
conditionalNode.conditionType = Conditional.ConditionType.Item;
conditionalNode.pointer01 = conditionMet;
conditionalNode.pointer02 = conditionNotMet;
conditionalNode.inputNode = rootFollow;
rootFollow = new Dialogue ("Char2", "Here is some dialogue that directly follows the root.");
rootFollow.pointer01 = conditionalNode;
rootFollow.isDirect = false;
rootFollow.inputNode = root;
root = new Dialogue ("Char1", "Here is the root dialogue.");
root.pointer01 = rootFollow;
root.isDirect = true;
}
Your order of instantiation feels backwards to me. Perhaps that was due to an earlier attempt to fix the dependency issues. In general, though, I recommend creating things in their ordinary order, and interleave the creation/initialization of later items into the creation/initialization of earlier items. You don’t have to set all properties of a single item before creating another item and setting its properties.
void Start()
{
root = new Dialogue ("Char1", "Here is the root dialogue.");
root.isDirect = true; // non-relational property
rootFollow = new Dialogue ("Char2", "Here is some dialogue that directly follows the root.");
rootFollow.isDirect = false; // non-relational property
rootFollow.inputNode = root; // up-stream reference
root.pointer01 = rootFollow; // down-stream reference
conditionalNode = new Conditional ();
conditionalNode.isConditionMet = false; // non-relational property
conditionalNode.conditionType = Conditional.ConditionType.Item;
conditionalNode.inputNode = rootFollow; // up-stream reference
rootFollow.pointer01 = conditionalNode; // down-stream reference
conditionMet = new Dialogue ("Char1", "Oh, you met the condition?");
conditionMet.inputNode = conditionalNode; // up-stream reference
conditionalNode.pointer01 = conditionMet; // down-stream reference
conditionNotMet = new Dialogue ("Char1", "Oh, you haven't met the condition yet.");
conditionNotMet.isDirect = false; // non-relational property
conditionNotMet.inputNode = conditionalNode; // up-stream reference
conditionNotMet.pointer01 = conditionalNode; // loop-back down-stream reference
conditionalNode.pointer02 = conditionNotMet; // down-stream reference}
Notice how I create each object, initialize its non-relational and up-stream properties only, and then move on to the next item. And at the end of initializing each item, I point the up-stream object at the newly created down-stream object, because I finally have both objects defined. The only time I don’t have to delay this process is when assigning a down-stream reference back up to an object that exists up-stream due to the dialogue graph looping back to a place where it had already been.
Cheers for taking the time out for the great reply man, it has really helped me out. Really appreciate you going the extra length to create an example (with very useful comments) for me as well, now I understand where I was going wrong, and hopefully won’t make the mistake again.