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

Sheetworker: utilize attribute data outside of the getAttrs function

1542677089
vÍnce
Pro
Sheet Author
I know there's a simple solution but my js knowledge is VERY limited.  I need to grab an attribute's value ( @{spell-fail}   ) from within the scope of  getAttrs  in order to do something in a "parent" function.  How can I use the currSpellFail variable outside of getAttrs scope?  TIA example    function doSomething(){ var currSpellFail function getCurrentSpellFail(value) { getAttrs(["spell-fail"], function(v) { var currSpellFail = parseInt(v["spell-fail"], 10) || 0; return currSpellFail; }); } // I need to do something with spell-fail out }
1542691489

Edited 1542691674
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Unfortunately, you can't since we can't use promises or async/await. You need to do everything within the getAttrs call back. Edit, the best way is to do a single getAttrs of every attribute you could conceivably need and then you can simply code as if it was synchronous within the call back.
1542693105
vÍnce
Pro
Sheet Author
Scott C. said: Unfortunately, you can't since we can't use promises or async/await. You need to do everything within the getAttrs call back. Edit, the best way is to do a single getAttrs of every attribute you could conceivably need and then you can simply code as if it was synchronous within the call back. No wonder I couldn't get this to work.  ;-) I'll do some more digging on the existing code(pf community sheet) I'm sure Chris created a module that grabs all the attribute data.  Thanks Scott