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

[Sheet workers] Delaying sheet workers

1540136216

Edited 1540138807
Jakob
Sheet Author
API Scripter
Is there any way to reliable delay execution of a function from within sheet workers? Using setTimeout() or _.delay() results in the sheet worker losing context, and you get the error message Character Sheet Error: Trying to do setAttrs when no character is active in sandbox. I mean, I could always just count to a billion or so, but that seems extremely wasteful.
1540138987

Edited 1540139176
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Nope, you can't do anything that removes it from the current execution instance (well, except for the asynchronous sheetworkers of course). So, _.delay, Promises, async/await, etc. are all off the table. I'd love to see the ability to pass a this object to sheetworkers to force them to use a specific instance, then I think you could use delays and async/await which would drastically improve what you can do with sheetworkers. What problem are you trying to handle in your sheet Jakob?
1540139277

Edited 1540139474
Jakob
Sheet Author
API Scripter
Damn! Thanks for confirming this, though. I want to do a rest button that displays some feedback (change "Rest" to "Rested!" for a few seconds, then goes back to its initial state). I guess there might also be a solution using CSS transitions, but I was hoping to avoid that ... ah well. I'd love to see the ability to pass a this object to sheetworkers to force them to use a specific instance, then I think you could use delays and async/await which would drastically improve what you can do with sheetworkers. That'd be great. Promises alone would simplify some things considerably. And with async/await you could just tell everyone who is scared by asynchronicity to use those and pretend everything is synchronous :).