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

Character Sheet Error: Trying to do {function} when no character is active in sandbox.

1487188393

Edited 1487188458
Lithl
Pro
Sheet Author
API Scripter
This error applies to both setAttrs and getAttrs, and possibly other sheet worker functions, but those are the two I've encountered. At its root, it may be the same problem that Stephen L posted about 4 months ago:  sheet worker - setAttrs callback doesn't work . Context: I am trying to write a utility function for sheet worker scripts which will calculate the value of an autocalc field, so that autocalc+sheet workers can play nicely together. I believe I have my utility function working correctly, or close to it, but making it useful  appears impossible with this error. My function returns a Promise which, when resolved, provides an object similar to the callback parameter in getAttrs see usage: on('sheet:opened change:a change:b', function() {     getAttrs(['a', 'b'], function(values) {         var a = parseFloat(values.a);         var b = parseFloat(values.b); // @{c} === "@{a}**@{b}"         resolveAutocalc (['c']).then(function(values) { // c === Math.pow(a, b)             var c = values.c; // Character Sheet Error: Trying to do setAttrs when no character is active in sandbox.             setAttrs({                 d: Math.round(Math.floor(c) * (a / b)) + Math.abs(a - b)             });         });     }); }); on('sheet:opened change:a change:b', function() { resolveAutocalc (['c']).then(function(values) {         var c = values.c; // Character Sheet Error: Trying to do getAttrs when no character is active in sandbox.     getAttrs(['a', 'b'], function(values) {         var a = parseFloat(values.a);         var b = parseFloat(values.b);             setAttrs({                 d: Math.round(Math.floor(c) * (a / b)) + Math.abs(a - b)             });         });     }); }); The Promise code is not escaping the sheet worker sandbox ( window  is still a DedicatedWorkerGlobalScope object), but it does seem to be getting detached from the character triggering the sheet worker event.
1487800443
Stephen Koontz
Forum Champion
Marketplace Creator
Sheet Author
API Scripter
Compendium Curator
Brian, Riley gave a response to this issue a little while ago: <a href="https://app.roll20.net/forum/post/4156526/sheet-wo" rel="nofollow">https://app.roll20.net/forum/post/4156526/sheet-wo</a>... Let me know if you have any questions on his waterfall solution, which works even if it isn't as modular as you'd like.
1487828389
Lithl
Pro
Sheet Author
API Scripter
At a glance, it looks like his waterfall might &nbsp;give me a way to rewrite my function, but it'll take some work so I can't give you an answer on that right now. Conceptually, the setup I've got is calling getAttrs recursively, and the bottom of the recursive stack is shifted off into async execution which doesn't occur until the top getAttrs is done.
1488003353
Lithl
Pro
Sheet Author
API Scripter
Thanks, Steve! I managed to create a modified version of Riley's waterfall function and used it to implement my resolveAutocalc function. It appears to work just fine: // @{a} = "13" // @{b} = "1.4" // @{c} = "@{a}**@{b}" on('sheet:opened change:a change:b', function() { resolveAutocalc('c', (v) =&gt; console.log(v)); // v = { a: 13, b: 1.4, c: 36.26775666655811 } }); I should hopefully be able to share the code soon. =)