Callback

Callbacks are choices that determine the outcome of later decisions, or even are just referred to, in later scenes.

The following snippet goes in the Code Panel of your project in Eko Studio, inside the onReady function.
Don’t forget to replace the Node IDs, variable names and values with the ones in your project.

// Variable dataSet
const subjects = {
    'node_starTrek': 'Picard',
    'node_drink': 'Coke',
    'node_twilight': 'Team Ed...'
};

// Initialization of the 'subject' Variable
player.variables.register({
    name: 'subject',
    action: 'set',
    initialValue: '',
    dataSet: subjetcs
});

// Callback Decision
player.variables.connect({
    from: 'node_scene_b1',
    to: function(variables) {
        if (variables.subject === 'Picard') {
            return 'node_picard';
        }
        if (variables.subject === 'Coke') {
            return 'node_coke';
        }
        if (variables.subject === 'Team Ed...') {
            return 'node_teamEd...';
        }
    },
    evaluateOn: 'playlistpush' // This determines when to evaluate the value of the 'subject' variable.
});

Code Breakdown

To get a better grasp of how this code works, let’s go through a simple scenerio - step by step:

  1. In Scene A you are presented with 3 choices. You choose Drink by clicking the corresponding button.
  2. The node Drink (ID node_drink) will start.
  3. The subject variable will be set to Coke.
    // Initialization of the 'subject' Variable
    player.variables.register({
     name: 'subject',
     action: 'set',
     initialValue: '',
     dataSet: subjects
    });
    
    This happens because we provided the subjects dataSet when we registered the variable. This dataSet dictates which value should be assigned to the variable, depending on the currently playing node.
    // Variable dataSet
    const subjects = {
     'node_starTrek': 'Picard',
     'node_drink': 'Coke',
     'node_twilight': 'Team Ed...'
    };
    
  4. Upon the push of node_scene_b1 (Scene B1) to the playlist, the value of subject will be checked to determine which node will come next.
    // Callback Decision
    player.variables.connect({
     from: 'node_scene_b1',
     to: function(variables) {
         if (variables.subject === 'Picard') {
             return 'node_picard';
         }
         if (variables.subject === 'Coke') {
             return 'node_coke';
         }
         if (variables.subject === 'Team Ed...') {
             return 'node_teamEd...';
         }
     },
     evaluateOn: 'playlistpush' // This determines when to evaluate the value of the 'subject' variable.
    });
    
    In this case the next node will be node_coke (Coke).

If you’re aiming for a more complex Callback, the Variables Plugin API will be of great help.
You can also discover how to create a more complete experience by checking out our Docs.

Rate this page: X
Tell us more!