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

Enable/Disable script button not working/intermittent

June 24 (10 years ago)
Lucian
Pro
API Scripter
I mentioned this over on the API forum but I think I've now got a better handle on the problem so I thought I'd report it here. The Enable/Disable button for API scripts has a nasty race condition bug which means it basically never works for me (and others). The handler looks like this (thank you for not obfuscating your JS!):

$(".togglescript").on("click", function() {
var $parent = $(this).parents(".script");
var scriptid = $parent.attr("id").replace("script-", "");
       var othis = this;
       if($(this).hasClass("active")) {
         $.post("/campaigns/toggle_script/730264/" + scriptid, {state: "inactive"}, function(data) {
           notifier.child("scriptrestart").set(true);
           notifier.child("errorlock").set(null);
           $(othis).removeClass("active").addClass("inactive").text("Enable Script");
         });
       }
       else {
         $.post("/campaigns/toggle_script/730264/" + scriptid, {state: "active"}, function(data) {
           notifier.child("scriptrestart").set(true);
           notifier.child("errorlock").set(null);
           $(othis).removeClass("inactive").addClass("active").text("Disable Script");
         });
       }
       window.location.href = window.location.href + "";
     });
The problem seems to be that window.location.href line at the bottom. I think in a lot of cases, the page is getting refreshed before the post to disable/enable the script even gets off my computer (this will no doubt depend on the latency of the connection and the speed of the computer). Consequently, most of the time the button just doesn't work at all. If I put a breakpoint in firebug it works flawlessly, because obviously there's then plenty of time for the request to be processed. Is there really any reason to refresh the page here? If there is, is there any reason why it can't happen inside the callback from the POST so you can be sure the request has gone through?

Cheers,

Lucian
June 24 (10 years ago)
Hello Lucian,

Thanks for making us aware of the bug. I've recorded it for the other devs to see and we should hopefully have a fix soon.

Thanks!