Script with setTimeout stops randomly

edited April 16 in MAIN

When testing the scripts, I have trouble understanding how they work. 

The function stops randomly after 1, 2 or 3 seconds, whereas it's supposed not to stop before changing column. 

I must have missed something?

Thank you.

here is the script (I cannot attached javascript)

function blinking_light(){
   Millumin.setLayerOpacity('lighty_layer', Math.random())
   setTimeout(blinking_light, 40);
}
blinking_light();

Comments

  • Hello @deuzair,

    Thank you for your feedback. Philippe

    Indeed, this is a race condition, where the script ends before it sets the timeout. This will be fixed soon in next version. Let me know if you need an intermediate version.

    A solution would be to code it as below (better in my opinion) :

    function blinking_light()
    {
       Millumin.setLayerOpacity('lighty_layer', Math.random())
    }
    setInterval(blinking_light, 1)
    

    Best. Philippe

    PS : you can now attach JS and TOX files

  • thank you Philippe !

Sign In or Register to comment.