Skip to main content
Participating Frequently
March 1, 2016
Question

Javascript Timers on two slides interfering with each other

  • March 1, 2016
  • 2 replies
  • 425 views

Hello,

I am developing training gamification and I have a Javascript Timer embedded in Slide 8 and one on Slide 12. The timer on slide 8 seems to interfere with Slide 12s if I get to slide 12 too early. Is there a way to stop all javascript executing on slide 8 once I exit slide 8 on success of a drag and drop?

Thanks,

Jay

    This topic has been closed for replies.

    2 replies

    TLCMediaDesign
    Inspiring
    March 2, 2016

    It all depends on how the timer is constructed. You should be able to use clearInterval() if the timer is constructed with setInterval.

    Participating Frequently
    March 2, 2016

    Added clearInterval command in if statement....but 2nd timer doesn't work well (goes too fast) when done with first script and timer keeps going seems to make 2nd timer mess up. The CLearInterval didn't seem to stop the first timer from making second timer go too fast.

    Thanks

    var duration =20 * 1;

    var decrementer= duration;

    var minutes;

    var seconds;

    var displayMe;

    var countdown = setInterval(updateMessage, 1000);

    function updateMessage() {

    //The 10 specifies the radix

    minutes = parseInt(decrementer / 60, 10);

    seconds = parseInt(decrementer % 60, 10);

    //Formatting ..

    minutes = minutes < 10 ? "0" + minutes : minutes;

    seconds = seconds < 10 ? "0" + seconds : seconds;

    displayMe = 0 + ":" +seconds;

    window.cpAPIInterface.setVariableValue('captivateTimer',displayMe);

    decrementer = decrementer-1;

    if (decrementer< 0) {

    clearInterval(countdown);

    var currentSlide=window.cpAPIInterface.getVariableValue('cpInfoCurrentSlide');

    if(currentSlide==9){

    window.cpAPIInterface.setVariableValue('cpCmndGotoSlide',10);

    }

    }

    if(currentSlide>9){clearInterval(0)};

    }

    function getRandomInt (min,max) {

    var jsRandomNumber = Math.floor(Math.random()*(max-min+1))+min;

    //alert(jsRandomNumber);

    window.cpAPIInterface.setVariableValue('visitorScore',jsRandomNumber);

    //alert('in getRandomInt');

    }

    getRandomInt(6,9);

    Participating Frequently
    March 2, 2016

    Do you know if the same variable names are used in two different Javascripts, will the values get shared? That could be my problem if the variables are shared.

    John T Smith
    Community Expert
    Community Expert
    March 1, 2016

    Provide the name of the program you are using so a Moderator may move this message to the correct program forum

    This Cloud forum is not about help with program problems... a program would be Photoshop or Lighroom or Muse or ???

    Participating Frequently
    March 1, 2016

    Its in Adobe Captivate...thanks