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 with Promises in sheet worker

Whenever this code snippet runs, I get an error: "Character Sheet Error: Trying to do setAttrs when no character is active in sandbox." I simplified the example and just wrapped getAttrs and setAttrs in promises, but the problem persists any time I use multiple promises. <input type="text" name="attr_testItem"/> <input type="text" name="attr_testResult"/> <script type="text/worker"> 'use strict'; function _get(valuesArray){ return new Promise((resolve,reject) => { getAttrs(valuesArray,function(values){ console.log(values); resolve(values) }); }); } function _set(values){ console.log('trying set'); console.log(values); return new Promise((resolve,reject) => { setAttrs(values,null,function(){ resolve(); }); }); } on('change:testitem',function(eventInfo){ console.log('change detected.'); _get(['testItem']).then(values => { console.log('.then values - '); console.log(values); _set({ testResult: values.testItem }).then(() => { console.log('set success'); }).catch(err => console.log('set fail. ' + err)); }); }); </script>
1532580196
Jakob
Sheet Author
API Scripter
Promises don't work with sheet workers (they lose the character context), sorry.
*shakes fist in rage* Meh, I'll get over it.  TY for the heads up. :D