Incrementing commands in a function

I am trying to write a function that will give a new set of commands each time the function runs. This function will be attached to one single button that updates each time

The first time:
playFirst = function(){
var symbolInstance = hypeDocument.getSymbolInstanceById(‘userName1’)
symbolInstance.startTimelineNamed(‘play’, hypeDocument.kDirectionForward)
}

The second time:
playSecond = function(){
var symbolInstance = hypeDocument.getSymbolInstanceById(‘userName2’)
symbolInstance.startTimelineNamed(‘play’, hypeDocument.kDirectionForward)
}

and so on…

What is the syntax to make this work?

Hi @courtney

Basically you want some kind of trigger that changes each time the function runs and then run a conditional on that trigger to call / run a set of commands. Like:

if (trigger == 1) {
   // do something
    trigger++;
} else if (trigger == 2) {
    // do something else
    trigger++;
}

Run a function on scene load that sets trigger

trigger = 1;
1 Like

Thank you :slight_smile:

How would you get the function to start over once it reaches 5?

Solution:

set another trigger that calls trigger = 1, where/when you want the function to start over

Is there a way to do this using user input? The user types a specific word that triggers the increment animation function?

Sure, depending on how you are getting the input. I’m going to assume an input tag.

var word = hypeDocument.getElementById('user-input-field').value;

if (word.toLowerCase() == "word-to-check") { // toLowerCase() does what it says and turns input value to lowercase
    hypeDocument.functions().name_of_function_that_contains_increment_animation();
    trigger = 1; // this is to make sure the animation starts at the beginning.
}
2 Likes

you rock! Thanks