Incrementing commands in a function


(Courtney Vigo) #1

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?


#2

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;

(Courtney Vigo) #3

Thank you :slight_smile:


(Courtney Vigo) #4

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


(Courtney Vigo) #5

Solution:

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


(Courtney Vigo) #6

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


#7

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.
}

(Courtney Vigo) #8

you rock! Thanks