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

[workerscript] Repeating Sections Help

1480610819
Jonathan P.
Pro
Sheet Author
So, it doesn't currently appear to do anything, not sure if I'm messing up something simple on the code. I have the following code that works correctly onChange, but I need a code to run to update all the values like the onchange, when an attribute is changed/updated. So I'm trying to make a function call that will be called to run within the onChange's of all the attributes. (also the onChange is on line 1238 on&nbsp; <a href="https://github.com/BuildAndDie/roll20-character-sheets/blob/master/Open%20Legend%20Basic%20by%20Great%20Moustache/Open%20Legend.html" rel="nofollow">https://github.com/BuildAndDie/roll20-character-sheets/blob/master/Open%20Legend%20Basic%20by%20Great%20Moustache/Open%20Legend.html</a> haven't put the function version in yet, but pasted below) // On Change for calculating rolls for Actions on("change:repeating_actions:action_attribute change:repeating_actions:dice_d20", function() { getAttrs(["repeating_actions_action_attribute", "repeating_actions_dice_d20", "agility_score", "agility_dice_modifier", "fortitude_score", "fortitude_dice_modifier", "might_score", "might_dice_modifier", "learning_score", "learning_dice_modifier", "logic_score", "logic_dice_modifier", "perception_score", "perception_dice_modifier", "will_score", "will_dice_modifier", "deception_score", "deception_dice_modifier", "persuasion_score", "persuasion_dice_modifier", "presence_score", "presence_dice_modifier", "alteration_score", "alteration_dice_modifier", "creation_score", "creation_dice_modifier", "energy_score", "energy_dice_modifier", "entropy_score", "entropy_dice_modifier", "influence_score", "influence_dice_modifier", "movement_score", "movement_dice_modifier", "prescience_score", "prescience_dice_modifier", "protection_score", "protection_dice_modifier"], function(values) { var score = 0; if(values.repeating_actions_action_attribute === "Agility") { score = values.agility_score*1 + values.agility_dice_modifier*1; } else if(values.repeating_actions_action_attribute === "Fortitude") { score = values.fortitude_score*1 + values.fortitude_dice_modifier*1; } else if(values.repeating_actions_action_attribute === "Might") { score = values.might_score*1 + values.might_dice_modifier*1; } else if(values.repeating_actions_action_attribute === "Learning") { score = values.learning_score*1 + values.learning_dice_modifier*1; } else if(values.repeating_actions_action_attribute === "Logic") { score = values.logic_score*1 + values.logic_dice_modifier*1; } else if(values.repeating_actions_action_attribute === "Perception") { score = values.perception_score*1 + values.perception_dice_modifier*1; } else if(values.repeating_actions_action_attribute === "Will") { score = values.will_score*1 + values.will_dice_modifier*1; } else if(values.repeating_actions_action_attribute === "Deception") { score = values.deception_score*1 + values.deception_dice_modifier*1; } else if(values.repeating_actions_action_attribute === "Persuasion") { score = values.persuasion_score*1 + values.persuasion_dice_modifier*1; } else if(values.repeating_actions_action_attribute === "Presence") { score = values.presence_score*1 + values.presence_dice_modifier*1; } else if(values.repeating_actions_action_attribute === "Alteration") { score = values.alteration_score*1 + values.alteration_dice_modifier*1; } else if(values.repeating_actions_action_attribute === "Creation") { score = values.creation_score*1 + values.creation_dice_modifier*1; } else if(values.repeating_actions_action_attribute === "Energy") { score = values.energy_score*1 + values.energy_dice_modifier*1; } else if(values.repeating_actions_action_attribute === "Entropy") { score = values.entropy_score*1 + values.entropy_dice_modifier*1; } else if(values.repeating_actions_action_attribute === "Influence") { score = values.influence_score*1 + values.influence_dice_modifier*1; } else if(values.repeating_actions_action_attribute === "Movement") { score = values.movement_score*1 + values.movement_dice_modifier*1; } else if(values.repeating_actions_action_attribute === "Prescience") { score = values.prescience_score*1 + values.prescience_dice_modifier*1; } else if(values.repeating_actions_action_attribute === "Protection") { score = values.protection_score*1 + values.protection_dice_modifier*1; } var number = calcAttributeDiceNumber(score); var type = calcAttributeDiceType(score); var roll = ""; if(score === 0) { roll = "[[?{Do you have Advantage or Disadvantage?|Neither,1d20!!|Advantage,2d20!!kh1|Disadvantage,2d20!!kl1}]]"; } else { roll = "[[" + values.repeating_actions_dice_d20 + " + [[" + number + "+?{# of Advantage/Disadvantage Dice|0}]]" + type + "k?{Do you have Advantage or Disadvantage?|Neither,h|Advantage,h|Disadvantage,l}" + number + "]]"; } setAttrs({ "repeating_actions_dice_roll": roll }); }); }); Attempt to make a function to go through all the repeating actions. function calcAllActionRolls () { getSectionIDs("repeating_actions", function(actionsArray) { var update = {}; _.each(actionsArray, function(currentID, i) { getAttrs(["repeating_actions_" + currentID + "_action_attribute", "repeating_actions_" + currentID + "_dice_d20", "agility_score", "agility_dice_modifier", "fortitude_score", "fortitude_dice_modifier", "might_score", "might_dice_modifier", "learning_score", "learning_dice_modifier", "logic_score", "logic_dice_modifier", "perception_score", "perception_dice_modifier", "will_score", "will_dice_modifier", "deception_score", "deception_dice_modifier", "persuasion_score", "persuasion_dice_modifier", "presence_score", "presence_dice_modifier", "alteration_score", "alteration_dice_modifier", "creation_score", "creation_dice_modifier", "energy_score", "energy_dice_modifier", "entropy_score", "entropy_dice_modifier", "influence_score", "influence_dice_modifier", "movement_score", "movement_dice_modifier", "prescience_score", "prescience_dice_modifier", "protection_score", "protection_dice_modifier"], function(v) { var score = 0; if(v["repeating_actions_" + currentID + "_action_attribute"] === "Agility") { score = values.agility_score*1 + values.agility_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Fortitude") { score = values.fortitude_score*1 + values.fortitude_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Might") { score = values.might_score*1 + values.might_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Learning") { score = values.learning_score*1 + values.learning_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Logic") { score = values.logic_score*1 + values.logic_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Perception") { score = values.perception_score*1 + values.perception_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Will") { score = values.will_score*1 + values.will_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Deception") { score = values.deception_score*1 + values.deception_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Persuasion") { score = values.persuasion_score*1 + values.persuasion_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Presence") { score = values.presence_score*1 + values.presence_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Alteration") { score = values.alteration_score*1 + values.alteration_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Creation") { score = values.creation_score*1 + values.creation_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Energy") { score = values.energy_score*1 + values.energy_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Entropy") { score = values.entropy_score*1 + values.entropy_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Influence") { score = values.influence_score*1 + values.influence_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Movement") { score = values.movement_score*1 + values.movement_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Prescience") { score = values.prescience_score*1 + values.prescience_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Protection") { score = values.protection_score*1 + values.protection_dice_modifier*1; } var number = calcAttributeDiceNumber(score); var type = calcAttributeDiceType(score); var roll = ""; if(score === 0) { roll = "[[?{Do you have Advantage or Disadvantage?|Neither,1d20!!|Advantage,2d20!!kh1|Disadvantage,2d20!!kl1}]]"; } else { roll = "[[" + v["repeating_actions_" + currentID + "_dice_d20"] + " + [[" + number + "+?{# of Advantage/Disadvantage Dice|0}]]" + type + "k?{Do you have Advantage or Disadvantage?|Neither,h|Advantage,h|Disadvantage,l}" + number + "]]"; } update["repeating_actions_" + currentID + "_dice_roll"] = roll; setAttrs(update); // setAttrs({ // "repeating_actions_" currentID + "_dice_roll": roll // }); }); }); }); };
1480638044
Jonathan P.
Pro
Sheet Author
After a few iterations of trial and error, this code is now working. I know I can optimize it quite a bit better, but at this point it is working, so I'll clean up the code later: function calcAllActionRolls () { var update = {}; var score = 0; var number = 0; var type = ""; var roll = ""; getSectionIDs("repeating_actions", function(actionsArray) { if(actionsArray.length &gt; 0) { _.each(actionsArray, function(currentID, i) { getAttrs(["repeating_actions_" + currentID + "_action_attribute", "repeating_actions_" + currentID + "_dice_d20", "agility_score", "agility_dice_modifier", "fortitude_score", "fortitude_dice_modifier", "might_score", "might_dice_modifier", "learning_score", "learning_dice_modifier", "logic_score", "logic_dice_modifier", "perception_score", "perception_dice_modifier", "will_score", "will_dice_modifier", "deception_score", "deception_dice_modifier", "persuasion_score", "persuasion_dice_modifier", "presence_score", "presence_dice_modifier", "alteration_score", "alteration_dice_modifier", "creation_score", "creation_dice_modifier", "energy_score", "energy_dice_modifier", "entropy_score", "entropy_dice_modifier", "influence_score", "influence_dice_modifier", "movement_score", "movement_dice_modifier", "prescience_score", "prescience_dice_modifier", "protection_score", "protection_dice_modifier"], function(v) { update = {}; score = 0; if(v["repeating_actions_" + currentID + "_action_attribute"] === "Agility") { score = v.agility_score*1 + v.agility_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Fortitude") { score = v.fortitude_score*1 + v.fortitude_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Might") { score = v.might_score*1 + v.might_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Learning") { score = v.learning_score*1 + v.learning_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Logic") { score = v.logic_score*1 + v.logic_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Perception") { score = v.perception_score*1 + v.perception_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Will") { score = v.will_score*1 + v.will_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Deception") { score = v.deception_score*1 + v.deception_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Persuasion") { score = v.persuasion_score*1 + v.persuasion_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Presence") { score = v.presence_score*1 + v.presence_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Alteration") { score = v.alteration_score*1 + v.alteration_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Creation") { score = v.creation_score*1 + v.creation_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Energy") { score = v.energy_score*1 + v.energy_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Entropy") { score = v.entropy_score*1 + v.entropy_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Influence") { score = v.influence_score*1 + v.influence_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Movement") { score = v.movement_score*1 + v.movement_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Prescience") { score = v.prescience_score*1 + v.prescience_dice_modifier*1; } else if(v["repeating_actions_" + currentID + "_action_attribute"] === "Protection") { score = v.protection_score*1 + v.protection_dice_modifier*1; } number = calcAttributeDiceNumber(score); type = calcAttributeDiceType(score); roll = ""; if(score === 0) { roll = "[[?{Do you have Advantage or Disadvantage?|Neither,1d20!!|Advantage,2d20!!kh1|Disadvantage,2d20!!kl1}]]"; } else { roll = "[[" + v["repeating_actions_" + currentID + "_dice_d20"] + " + [[" + number + "+?{# of Advantage/Disadvantage Dice|0}]]" + type + "k?{Do you have Advantage or Disadvantage?|Neither,h|Advantage,h|Disadvantage,l}" + number + "]]"; } update["repeating_actions_" + currentID + "_dice_roll"] = roll; setAttrs(update); }); }); } }); };