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 .
×
Advertisement Create a free account

How to retrieve data from repeating and non-repeating sections together in a Sheet Worker Script?

1493845954
Hello all, I'm currently working on a sheet worker script for my Dark Heresy 2.0 character sheet. This script is supposed to update a value in a repeating section that is calculated using values from the repeating section (repeating_cls:commonloreranks, repeating_cls:commonloremiscs) itself as well as two values from non-repeating areas (Intelligence, IntelligenceAdj). It works well when I don't add any of the values from non-repeating sections into the final score, but when I try and add the two non-repeating values it displays a blank. The main script: on("change:repeating_cls:commonloreranks change:repeating_cls:commonloremiscs", function() { getAttrs(["Intelligence", "Intelligenceadj","repeating_cls_commonloreranks", "repeating_cls_commonloremiscs", "repeating_cls_commonlorescores"], function(values) { var tempmod=10; tempmod=parseInt(values.repeating_cls_commonloreranks); if(tempmod == 0) {tempmod=-20;} else if (tempmod==1 || tempmod==2 || tempmod==3 || tempmod==4) {tempmod=(tempmod-1)*10;} else {tempmod=-900;} setAttrs({ repeating_cls_commonlorescores: (parseInt(values.repeating_cls_commonloremiscs) + tempmod) /* The one below doesn't work (when uncommented), the one above does work correctly repeating_cls_commonlorescores: (parseInt(values.intelligence) + parseInt(values.Intelligenceadj) + parseInt(values.repeating_cls_commonloremiscs) + tempmod) */ }); }); }); Is there something I'm missing in my script? How can I get it to correctly retrieve all the needed attributes? Thanks!
1493962142
Amanda the Amazon
Pro
Sheet Author
I noticed some discrepancies in your capitalization of Intelligence (the parseInt value is not capitalized) and IntelligenceAdj (listed with Adj capitalized up top, but now showing as capitalized in your script).
1494265594
Amanda, Thanks for your reply. I did some further testing, and it looks like the sheet workers just don't support retrieval of values outside the repeating section if the triggering event comes from a repeating section. I resolved my issue by creating some global variables with the following structure: //Latches any changed int values for lore calculations on("change:intelligence change:intelligenceadj", function() { getAttrs(["Intelligence", "Intelligenceadj"], function(values) { self.obj = self.obj || {}; self.obj.Intelligence = values.Intelligence; self.obj.Intelligenceadj = values.Intelligenceadj; }); }); //Calculates the score for each individual CL on("change:repeating_cls:commonloreranks change:repeating_cls:commonloremiscs", function() { getAttrs(["repeating_cls_commonloreranks", "repeating_cls_commonloremiscs", "repeating_cls_commonlorescores"], function(values) { var tempmod = 10; tempmod = parseInt(values.repeating_cls_commonloreranks); if (tempmod == 0) {tempmod = -20;} else if (tempmod == 1 || tempmod == 2 || tempmod == 3 || tempmod == 4) {tempmod = (tempmod - 1) * 10;} else {tempmod = -900;} var Intelligence = self.obj.Intelligence; var Intelligenceadj = self.obj.Intelligenceadj; setAttrs({ repeating_cls_commonlorescores: (parseInt(Intelligence) + parseInt(Intelligenceadj) + parseInt(values.repeating_cls_commonloremiscs) + tempmod) }); }); });