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

Passing Variables from Repeating Sections and Non-Repeating sections into the same script.

Hello! Me again. I'm trying to make another script to assign two variables from one dropdown. :) This time, the main selected variable is inside the repeating section, but the values it's setting are outside, in the general skills section. I tried nesting the getAttr commands, but I'm getting an error that it isn't finding the value from those non-repeating variables when I send the info to the attack template. Can you look at it and see if I did it right, or if maybe my trouble is elsewhere. I think it is a problem in the script because when I try to compile it, I get: JSC_PARSE_ERROR: Parse error. Unterminated string literal at line 16 character 93 ...epeating_meleeWeapons_${id}_meleeWeaponMast`] = mast.specialWeaponMeleeMast'; ^ /*Melee Weapon Select*/ on("sheet:opened change:repeating_meleeWeapons", function() { getSectionIDs('repeating_meleeWeapons', function (idArray) { getAttrs(["heavyWeaponMeleeMast","specialWeaponMeleeMast","wrestlingMAMast","defenseTechniquesMast","offenseTechniquesMast","armedCombatMast","handToHandCombatMast"], function(mast){ getAttrs(idArray.map(id => `repeating_meleeWeapons_${id}_meleeWeaponSkill`), function (values) { console.log(values); // Logging all the approach key:value pairs console.log(idArray); // logging all row ids. Those missing from the values object above don't have an approach // attribute set, so they should default to air let setting = {}; idArray.forEach(function (id) { switch (values[`repeating_meleeWeapons_${id}_meleeWeaponSkill`]) { case '@{heavyWeaponMelee}': setting[`repeating_meleeWeapons_${id}_meleeWeaponMast`] = mast.heavyWeaponMeleeMast; break; case '@{specialWeaponMelee}': setting[`repeating_meleeWeapons_${id}_meleeWeaponMast`] = mast.specialWeaponMeleeMast'; break; case '@{wrestlingMA}': setting[`repeating_meleeWeapons_${id}_meleeWeaponMast`] = mast.wrestlingMAMast; break; case '@{defenseTechniques}': setting[`repeating_meleeWeapons_${id}_meleeWeaponMast`] = mast.defenseTechniquesMast; break; case '@{offenseTechniques}': setting[`repeating_meleeWeapons_${id}_meleeWeaponMast`] = mast.offenseTechniquesMast; break; case '@{armedCombat}': setting[`repeating_meleeWeapons_${id}_meleeWeaponMast`] = mast.armedCombatMast; break; default: setting[`repeating_renpckata_${id}_meleeWeaponMast`] = mast.handToHandCombatMast; // defaulting to handtohand in case the select was never changed } }); console.log(setting); // Logging the attributes we are about to set. setAttrs(setting); }); }); }); });
You have an extra ' at the end of that line. mast.specialWeaponMeleeMast'; should be mast.specialWeaponMeleeMast;
1519885028
GiGs
Pro
Sheet Author
API Scripter
That's an interesting construction. I've never seen nested getAttrs before. In the introduction you say, "the main selected variable is inside the repeating section, but the values it's setting are outside, in the general skills section."  But your function looks to me like the values it is setting are inside the repeating section. Am i misreading it?
Thanks, btw, I had to track down another typo, but Author X's fix got it generally working. This is from the Polaris sheet. What it is, is a script for the repeating section where you type in melee weapons. There's a drop-down for setting what skill you're using inside that repeating section. The problem is I needed to pass into the attack template not just the skill total, which the dropdown sets, but the skill master level for criticals, which is only part of the skill total. So the drop down where you do the selection is inside the repeating section, and the final set variable for the skill mastery level of that one weapon is being passed BACK into the repeating section, but the data it's using to set that variable is from the melee skill section, OUTSIDE the repeating section.
1519890705

Edited 1519890719
Jakob
Sheet Author
API Scripter
BTW some unsolicited advice: running multiple nested getAttrs is slower than just having one getAttrs statement that gets everything you want. You can use the ES6 spread syntax to merge together your arrays and get away with one getAttrs at the same effort (I've put it into a variable for readability): const attrNames = [ "heavyWeaponMeleeMast", "specialWeaponMeleeMast", "wrestlingMAMast", "defenseTechniquesMast", "offenseTechniquesMast", "armedCombatMast", "handToHandCombatMast", ...idArray.map(id => `repeating_meleeWeapons_${id}_meleeWeaponSkill`) ]; getAttrs(attrNames, function (values) { // ... });
THanks, Jakob. I knew how to do the two things, but not how to combine them.