You are reading a single comment by @Mrbbp and its replies. Click here to read the full conversation.
  • Sorry @Gordon i do not understand the difference between the 2 versions..

    what do you mean by callback? is it the function define in the setInterval?

    I've tried reinitiate a setInterval at the end of 8 "danse"move but does not works... i've got an unknown interval error!
    I'm confused

    function mecatronique(myId) {
      var tirage = Math.random();
      if (tirage >0.95) {
        clearInterval(myId);
        var tm = 800;
        var compteurDanse = 0;
        var idDanse = setInterval( function(id) {
          console.log("danse");
          compteurDanse ++;
          if (compteurDanse >= 8) {clearInterval(id);var idM = setInterval(mecatronique, 500, idM);}
        }, tm, idDanse);
      } else {
        if (tirage >0.6) {
          console.log("bouge");
        }
      }
    }
    
    function onInit() {
      var idMeca = setInterval(mecatronique, 500, idMeca);
    }
    

    sorry for my ugly code

About

Avatar for Mrbbp @Mrbbp started