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

[Help] clearTimeout(t)

1367991896
Konrad J.
Pro
API Scripter
Hi guys, I'm sure its something stupid, but I just can't get this to work.  It keeps on bringing up an error. "ReferenceError: clearTimeout is not defined" Everything works except with the clearTimeout gets called. var t; .........     t=setTimeout(function(){         obj.set("status_dead",true);         sendChat("","Time's Up!!!")     },timer); .......             clearTimeout(t);
It looks as though perhaps clearInterval and clearTimeout may not be available in the sandbox. I don't know if that is intentional or not, but you could use another variable to check in your function to see if it should still run. That obviously isn't ideal if you are doing a lot of these, but it would work.
1367992837
Alex L.
Pro
Sheet Author
Isn't clearTimeout part of the window object? We don't have access to the window object as its not needed for scripts.
1367992921
Konrad J.
Pro
API Scripter
I was thinking that when I looked it up on the web, but how do you clear a setTimeout? Edit: and thanks guys for getting back to me so quick!!!
Alex L. said: Isn't clearTimeout part of the window object? We don't have access to the window object as its not needed for scripts. Yes, but they are super helpful and probably only because the window object in a browser is the default way to make something global. I think setInterval and setTimeout are also part of window in a browser, but we have them anyhow.
1367993310
Konrad J.
Pro
API Scripter
Ryan L said: It looks as though perhaps clearInterval and clearTimeout may not be available in the sandbox. I don't know if that is intentional or not, but you could use another variable to check in your function to see if it should still run. That obviously isn't ideal if you are doing a lot of these, but it would work. What I'm trying to do is a stop watch.  It all works, but I wanted the ability to cancel the timer if the user doesn't want to wait, lets say they set it to 5 minutes and they don't want to wait.
1367994643
Alex L.
Pro
Sheet Author
Ryan L said: Alex L. said: Isn't clearTimeout part of the window object? We don't have access to the window object as its not needed for scripts. Yes, but they are super helpful and probably only because the window object in a browser is the default way to make something global. I think setInterval and setTimeout are also part of window in a browser, but we have them anyhow. I expect Riley made an exception for then in that case as i believe the documentation said we have no window objects. I can understand why as a sleep would be dangerous so the only option is a time-out. I expect he will add it in if its needed in the next update.
This was just an oversight on my part. I will add them in the next update.
1368031240
Konrad J.
Pro
API Scripter
Riley D. said: This was just an oversight on my part. I will add them in the next update. No one is perfect, but you are close! :)  Thanks a bunch!!!
<a href="https://app.roll20.net/forum/post/149529/api-update-5-slash-8-state-object-persistence#post-149529" rel="nofollow">https://app.roll20.net/forum/post/149529/api-update-5-slash-8-state-object-persistence#post-149529</a>