Exit Points

Sometimes you will want to jump to a child node, but not immediately on making the decision or when the parent node ends, but on pre-defined points in time within the parent node.

The Exit Points snippet requires that you pre-define the exit points’ time in each node’s Metadata. Do so by following these steps:

  1. Open your project in Eko Studio and right click the node you wish to set exit points on. Choose “Get element ID and metadata”:

  2. Copy the following code:

    {
     "exitPoints": [
         21.04,
         82.9
     ]
    }
    

    And paste it into the Metadata editor:

  3. Add/modify the numerical values to match the points in the node’s time in which you would like to exit. Note that the values are in seconds, not frames. For example 82.9 would be 1 minute, 22 seconds and 900 milliseconds into the node. Finally, don’t forget to seperate each value with a comma!

The following snippet goes in the Code Panel of your project in Eko Studio, inside the onInit function.
It will iterate through each node’s metadata and set it’s exit points accordingly.

// Get an array of all available nodes
const allNodes = player.repository.get('all');

// Filter out any node without exit points set in their metadata
const nodesWithExitPoints = allNodes.filter(node => node.data && node.data.studio && node.data.studio.exitPoints );

// If the current node's decision was made then play the next node
function exitIfDecisionMade() {
    const currentDecision = player.decision.get(player.currentNode);
    if (currentDecision.state === 'made') {
        player.currentNodeIndex += 1;
    }
}

// Iterate through nodes with exit points
nodesWithExitPoints.forEach(nodeToExit => {
    const exitPoints = nodeToExit.data.studio.exitPoints

    // Double check that the node's metadata is valid
    if (!Array.isArray(exitPoints)) {
        console.error(`exitPoints for ${nodeToExit.id} is not an array! Please check your metadata and try again.`);
        return;
    }

    // Set an exit for each point in the node's time
    exitPoints.forEach(function(exitPoint) {
        nodeToExit.on(`timeupdate:${exitPoint}`, exitIfDecisionMade);
    });
});

Discover how to create a more complete experience by checking out our Docs.

Rate this page: X
Tell us more!