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

Accessing repeating sections using section IDs in sheet worker scripts

1467042919

Edited 1467131671
Okay guys, I'm building a custom character sheet from scratch for a homebrew Dark Heresy 2.0 / Rogue Trader hybrid (Rogue Trader 2.0). As part of this sheet I have different "tabs" for the final displayed character sheet and the excel-style data entry pages. On one of the data entry pages I let the players add different weapons and their characteristics to a repeating section, then I include checkboxes so they can select up to two weapons to display on the front page of the actual character sheet. My script is supposed to trigger when this checkbox is modified. As it stands, the script is trying to: a. return the complete array of repeating section IDs b. iterate through the array and see if each repeating section has the checkbox in question "checked" c. if the box is checked, the function should copy the associated section's weapon information over to the front display section d. if more than 2 checkboxes are checked (the front page limit), it should ignore any subsequent checkboxes Currently (even with (b) set to always true (code shown below has the conditional I'm actually trying to test), it seems like I'm unable to pull from repeating sections using the unique IDs, it instead just pulls from whichever repeating section triggered the worker script in the first place [I've also tried hardcoding it to pull from the string I store in str2 and I get nothing]) My questions: 1. Is there a better way to do this? 2. How do I properly access the properties of a repeating section using the ID? 3. How can I properly determine if a checkbox is "checked" or not? Here's the current code: (The repeating group I'm pulling from is called repeating_weapons, and the targets are two sections with names like dispweaponname, dispweaponname1, etc. The checkbox is called wpnselects) on("change:repeating_weapons:wpnselects", function() { getSectionIDs("repeating_weapons", function(idarray) { for(var i=0; i < idarray.length; i++) { //get the attributes from the repeating sections using their unique IDs var str1 = "repeating_weapons_"; var str2 = idarray[i]; str2 = str1.concat(str2); str1 = "_wpnselects"; str2 = str2.concat(str1); getAttrs([str2], function(values) { //this conditional should test if the checkbox from the section in question is "checked" if(values.repeating_weapons_wpnselects==1) { getAttrs([ "repeating_weapons_wpnnames", "repeating_weapons_wpnsingleshots", "repeating_weapons_wpnsemishots", "repeating_weapons_wpnautoshots", "repeating_weapons_wpnranges", "repeating_weapons_wpndmgs", "repeating_weapons_wpnpens", "repeating_weapons_wpnclipcurs", "repeating_weapons_wpnclipmaxs", "repeating_weapons_wpnweights", "repeating_weapons_wpnqualitys", "repeating_weapons_wpnnamespecials" ], function(values) { setAttrs({ dispwpnname: values.repeating_weapons_wpnnames, dispwpnsingleshot: values.repeating_weapons_wpnsingleshots, dispwpnsemishot: values.repeating_weapons_wpnsemishots, dispwpnautoshot: values.repeating_weapons_wpnautoshots, dispwpnrange: values.repeating_weapons_wpnranges, dispwpndmg: values.repeating_weapons_wpndmgs, dispwpnpen: values.repeating_weapons_wpnpens, dispwpnclipcur: values.repeating_weapons_wpnclipcurs, dispwpnclipmax: values.repeating_weapons_wpnclipmaxs, dispwpnquality: values.repeating_weapons_wpnquality, dispwpnspecial: values.repeating_weapons_wpnspecials }); }); } }); } }); });
Well, I think I found a setup that works: on("change:repeating_weapons:wpnselects", function() { getAttrs(["repeating_weapons_wpnselects"], function(v) { getSectionIDs("repeating_weapons", function(idarray) { if(idarray.length > 0) { var count = 0; _.each(idarray, function(currentID, i) { getAttrs(["repeating_weapons_" + currentID + "_wpnselects"], function(x) { var spellid = x["repeating_weapons_" + currentID + "_wpnselects"] if(spellid == 1 && count == 0) { count=count+1; getAttrs([ "repeating_weapons_" + currentID + "_wpnnames", "repeating_weapons_" + currentID + "_wpnsingleshots", "repeating_weapons_" + currentID + "_wpnsemishots", "repeating_weapons_" + currentID + "_wpnautoshots", "repeating_weapons_" + currentID + "_wpnranges", "repeating_weapons_" + currentID + "_wpndmgs", "repeating_weapons_" + currentID + "_wpnpens", "repeating_weapons_" + currentID + "_wpnclipcurs", "repeating_weapons_" + currentID + "_wpnclipmaxs", "repeating_weapons_" + currentID + "_wpnweights", "repeating_weapons_" + currentID + "_wpnqualitys", "repeating_weapons_" + currentID + "_wpnspecials" ], function(y) { setAttrs({ dispwpnname: y["repeating_weapons_" + currentID + "_wpnnames"], dispwpnsingleshot: y["repeating_weapons_" + currentID + "_wpnsingleshots"], dispwpnsemishot: y["repeating_weapons_" + currentID + "_wpnsemishots"], dispwpnautoshot: y["repeating_weapons_" + currentID + "_wpnautoshots"], dispwpnrange: y["repeating_weapons_" + currentID + "_wpnranges"], dispwpndmg: y["repeating_weapons_" + currentID + "_wpndmgs"], dispwpnpen: y["repeating_weapons_" + currentID + "_wpnpens"], dispwpnclipcur: y["repeating_weapons_" + currentID + "_wpnclipcurs"], dispwpnclipmax: y["repeating_weapons_" + currentID + "_wpnclipmaxs"], dispwpnweight: y["repeating_weapons_" + currentID + "_wpnweights"], dispwpnquality: y["repeating_weapons_" + currentID + "_wpnqualitys"], dispwpnspecial: y["repeating_weapons_" + currentID + "_wpnspecials"] }); }); } else if(spellid == 1 && count == 1) { count=count+1; getAttrs([ "repeating_weapons_" + currentID + "_wpnnames", "repeating_weapons_" + currentID + "_wpnsingleshots", "repeating_weapons_" + currentID + "_wpnsemishots", "repeating_weapons_" + currentID + "_wpnautoshots", "repeating_weapons_" + currentID + "_wpnranges", "repeating_weapons_" + currentID + "_wpndmgs", "repeating_weapons_" + currentID + "_wpnpens", "repeating_weapons_" + currentID + "_wpnclipcurs", "repeating_weapons_" + currentID + "_wpnclipmaxs", "repeating_weapons_" + currentID + "_wpnweights", "repeating_weapons_" + currentID + "_wpnqualitys", "repeating_weapons_" + currentID + "_wpnspecials" ], function(y) { setAttrs({ dispwpnname1: y["repeating_weapons_" + currentID + "_wpnnames"], dispwpnsingleshot1: y["repeating_weapons_" + currentID + "_wpnsingleshots"], dispwpnsemishot1: y["repeating_weapons_" + currentID + "_wpnsemishots"], dispwpnautoshot1: y["repeating_weapons_" + currentID + "_wpnautoshots"], dispwpnrange1: y["repeating_weapons_" + currentID + "_wpnranges"], dispwpndmg1: y["repeating_weapons_" + currentID + "_wpndmgs"], dispwpnpen1: y["repeating_weapons_" + currentID + "_wpnpens"], dispwpnclipcur1: y["repeating_weapons_" + currentID + "_wpnclipcurs"], dispwpnclipmax1: y["repeating_weapons_" + currentID + "_wpnclipmaxs"], dispwpnweight1: y["repeating_weapons_" + currentID + "_wpnweights"], dispwpnquality1: y["repeating_weapons_" + currentID + "_wpnqualitys"], dispwpnspecial1: y["repeating_weapons_" + currentID + "_wpnspecials"] }); }); } }); }); } }); }); }); This allows me to fill my two front-page boxes with the first two selected weapons from the input sheet. Done and done!