Sunday, August 8, 2010

Thinking out the program

Just taking some notes for myself on how to build out this choice interface from here out. This is still rough terminology.

First, each decision node has to be its own class; a decision node, or decNode, is comprised simply of two or more choices.

A choice is one of those choices, and each one contains a variable stating what the next decNode is.

FirstChoice, SecondChoice, ThirdChoice, and FourthChoice are the names of each choice under the decNodes, and each one also contains a variable called decY, which is different for each one of these. Using purely hypothetical numbers, FirstChoice.decY would be +10, SecondChoice.decY would be +5, ThirdChoice.decY would be -5, and FourthChoice.decY would be -10. This all relates specifically to how the decision tree chart will fill itself in. Each Choice and each decNode has a "name" variable for labeling purposes. Each decNode, of course, has the text corresponding to its narrative passage, and each Choice has text corresponding to what exactly the choice is.

Specifically: the chart starts at the first decision, moves forward by an "X" coordinate value with each decision, then moves up or down by the "Y" value contained in each choice's decY value, then creates the node referenced in the NextNode variable under each choice. Repeat for every node until we reach a decNode that has a boolean that says "LastChoice=true." We now have somewhat of a system that allows us to draw the chart procedurally, moving from one decNode containing multiple choices to another. We have one parser that automatically does this, alleviating me from having to sit down in Flash and draw the entire chart and reference its coordinates by hand, and we have a second parser that saves the user's decisions thus far in an array--with the array saving not the names of the choices but the decY variable for each one--and then traces through each one of those until the current decision node.

In the main program:
currentNode is the player's current choice node.

is the array containing the decY variables of all the player's previous choices, which the second parser uses to draw out their path.

op1, op2, op3, op4 are all corresponding to four buttons in the main program, namely the ones for the choices. They automatically fill themselves with currentNode.FirstChoice.text, and their event listeners reference functions that immediately substitute currentNode with currentNode.FirstChoice.nextNode. Their functions also parse through the prevNodes array until they count to the end of it, then add 1 to the last position and stick in currentNode.FirstChoice.decY at that position into the array.

The chart will draw itself, but it'll look sloppy as branches will end up crossing with one another and nodes will end up overlapping visually. It would go +5 for one decision, then for the next one go -5 and run straight into the +5 node for the next one, which isn't what we want to have happen right now. At least we have the basic logic for getting these charts to work, but we'll have to find a better way to get the nodes to diverge visually.

No comments:

Post a Comment