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

Referencing a repeating attr to change a repeating attr

1502574021
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
I don't understand why this is not working. I want the wound_modifier to report the correct info based on the damage type. However it is not sending that info. // Listen for sheet open or change to repeating type or remove type on('sheet:opened change:repeating_ranged_type remove:repeating_ranged_type', updatewoundmodifier ); // Update Wound Modifer function updatewoundmodifier() { getAttrs(['repeating_ranged_type'], function(v) { var attrs = {}; if (v.repeating_ranged_type === "Cutting (cut)") { repeating_ranged_wound_modifier = "x1.5"; } else if (v.repeating_ranged_type === "Impaling (imp)") { repeating_ranged_wound_modifier = "x2"; } else if (v.repeating_ranged_type === "Crushing (cr)") { repeating_ranged_wound_modifier = "x1"; } else if (v.repeating_ranged_type === "Small Piercing (pi-)") { repeating_ranged_wound_modifier = "x0.5"; } else if (v.repeating_ranged_type === "Piercing (pi)") { repeating_ranged_wound_modifier = "x1"; } else if (v.repeating_ranged_type === "Large Piercing (pi+)") { repeating_ranged_wound_modifier = "x1.5"; } else if (v.repeating_ranged_type === "Huge Piercing (pi++)") { repeating_ranged_wound_modifier = "x2"; } else if (v.repeating_ranged_type === "Burning (burn)") { repeating_ranged_wound_modifier = "x1"; } else if (v.repeating_ranged_type === "Corrosion (cor)") { repeating_ranged_wound_modifier = "x1"; } else if (v.repeating_ranged_type === "Fatigue (fat)") { repeating_ranged_wound_modifier = "x1"; } else if (v.repeating_ranged_type === "Toxic (tox)") { repeating_ranged_wound_modifier = "x1"; } setAttrs({ repeating_ranged_wound_modifier: repeating_ranged_wound_modifier }); }); }
1503131108

Edited 1503131173
Jakob
Sheet Author
API Scripter
Couple of problems: When the sheet:opened event is triggered, you are not actually in a repeating row context, so getting/setting via e.g. repeating_ranged_type does not work - you have to use getSectionIDs() to get all section IDs and then iterate over the IDs and construct your attribute names from there. For the in-section events, the notation is change:repeating_ranged:type. Note the colon after ranged. You don't need (and shouldn't have) the remove event, it doesn't make any sense to set an attribute in a removed section. Otherwise, your updatewoundmodifier() function should work when triggered from change:repeating_ranged:type. Remarks: "var attrs = {};" doesn't do anything, since you never use attrs again. This is probably more readable, and shorter, as a switch statement instead of if/else. You should declare variables before you use them, even if non-strict-mode Javascript doesn't require you to do that.