Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Simple setInterval not working

1713046771

Edited 1713046886
GM
Pro
This one is going to make me kick something when I find out why it isn't working. It seems pretty darned simple. I've placed test output in different parts of this code, and the only thing that doesnt' fire is the bits inside function flipper. WHY?? on("change:campaign:playerpageid",function(){     on("ready",function(){             var flip;         var currentPage = getObj("page",Campaign().get("playerpageid"));         sendChat("api","!token-mod --config players-can-ids|on");         if (currentPage.get("name")=="IronIntro"){             sendChat("api","!token-mod --ids -NvNSCFWJEsHckT-2n5b --set currentside|0");             flip = setInterval(flipper, 3000);         }         else {             clearInterval(flip);             flip = null;         }     }); }); function flipper(){     sendChat("api","!token-mod --api-as -NuNEyiUxtf09GGhur8L --ids -NvNSCFWJEsHckT-2n5b --set currentside|+1"); }
1713049357
timmaugh
Pro
API Scripter
I don't think your on('ready') is ever going to work like that. The way you have it, your on('ready') is in the campaign change event .. so you're registering a function to run when the campaign changes. When that callback function runs, it registers your on(cready') function... Except by then, the ready event has already fired (you only get the one), so nothing in the inner callback will actually ever run. The reverse is what you want... Have your on('ready') wrapper be the outside, so that it runs when the ready event fires. In there, you have your on('change:campaign:...') event, so its call back is properly registered at the right time. Then, withing that inner callback, you can put your call to flipper and it should run. I would suggest moving the flipper function in the on('ready') closure so that you don't pollute the global namespace (you might have to make the on('ready') function into an IIFE... on('ready', function (){ //... })(); Last, I'm not sure if setInterval is available in the sandbox... I've never had to use it. setTimeout is available...
SetInterval works. I’ve used it before. However, your fix is the fix. Hot Shizz! Thanks!