As we are already using linq

Instead of:
DialogueNode children = currentDialogue.GetAllChildren(currentNode).ToArray();
currentNode = nodes[0];

do
IEnumerable nodes = currentDialogue.GetAllChildren(currentNode);
currentNode = nodes.First(); (or FirstOrDefault())

As this doesn’t create a copy of the enumerable; (which ToArray() does)

1 Like

Wait i’m confused.

yes and thats why we can use first() instead of casting to an array first, which would lead to a copy of the ienumerable, however this does make the random stuff more complication

This looks great if you know you’ll always use the first element in the collection (but then again, why would we include other options if we only used the first). Once we begin filtering these elements, this will indeed complicate things.

You also want to leave open the possiblity of random answers… for example, when looking for Mother Hubbard’s foot cream, it may be that one of the guard has the foot cream… so you need to talk to all of the guard, but only one will have it. In my project, each of the guards says one of several random things when he’s talked to. “No, I don’t have any foot cream,” “I don’t have any, but if you find some I could use it too,” “Buzz off, can’t you see I’m busy.” It just makes things more… interesting.

Privacy & Terms