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 .
×

[Worker Sheet] How do i get the value from getAttrs(["repeating_skills_" + idarray[i] + "_skillspend"], function(x)

I have this code to get the sum from all the @{skillspend} but the x["repeating_skills_" + idarray[i] + "_skillspend"] doesn't return the value. How do i get this value? on("change:repeating_skills", function() { var total =0; getSectionIDs("repeating_skills", function(idarray) { for(var i=0; i < idarray.length; i++) { console.info("[getSectionIDs] "+i+": "+idarray[i]); console.info("repeating_skills_" + idarray[i] + "_skillspend"); getAttrs(["repeating_skills_" + idarray[i] + "_skillspend"], function(x) { total = total +x["repeating_skills_" + idarray[i] + "_skillspend"]; }); } }); });
1504656646

Edited 1504670762
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Getattrs is asynchronous, by the time the addition happens, i has been fully incremented. EDIT: now that I'm on my comp, try this code: on('change:repeating_skills',(skill)=>{ var total = 0, skillArr; getSectionIDs('repeating_skills',(IDs)=>{ skillArr=_.map(IDs,(i)=>{ return 'repeating_skills_'+i+'_skillspend'; }); getAttrs(skillArr,(skillSpend)=>{ total = _.reduce(skillSpend,(memo,s)=>{ return memo + s*1; },0); console.log(total); }); }); });
It worked! Thank you very much.
1504699529
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Glad to hear.