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

Sheetworker Help with Template Literals

I am trying to combine two similar sheetworkers into a single piece of code with template literals, but I am having no success. I still feel like a chimp given two computers and I am banging them together attempting to code! :-D on("change:repeating_melee:mwpn_damage_die_type", function() {     getAttrs(["repeating_melee_mwpn_damage_die_type"], function(values) {         switch(values.repeating_melee_mwpn_damage_die_type) {             case "0":                 setAttrs({                     "repeating_melee_mwpn_template": "DnD35NoDamage"                 });             break;             default:                 setAttrs({                     "repeating_melee_mwpn_template": "DnD35Attack"                 });         }     }); }); on("change:repeating_ranged:rwpn_damage_die_type", function() {     getAttrs(["repeating_ranged_rwpn_damage_die_type"], function(values) {         switch(values.repeating_ranged_rwpn_damage_die_type) {             case "0":                 setAttrs({                     "repeating_ranged_rwpn_template": "DnD35NoDamage"                 });             break;             default:                 setAttrs({                     "repeating_ranged_rwpn_template": "DnD35Attack"                 });         }     }); }); Here is my attempt. I don't see either of my console.log messages. I suspect I am doing something wrong in the bolded if statement. Can I use a switch statement with template literals? let attackcategories = ['melee_mwpn', 'ranged_rwpn']; attackcategories.forEach(function (attackcategory) {     let attrs = [`repeating_${attackcategory}_damage_die_type`];     on(attrs.map(str => `change:${str}`).join(' '), function () {         getAttrs(attrs, function (values) {                          if (parseInt(values[`repeating_${attackcategory}_damage_die_type`], 10) == 0) {                 console.log('====================== ZERO =====================');                 let setting = {};                 setting[`repeating_${attackcategory}_template`] = "DnD35NoDamage";             } else {                 console.log('====================== NON ZERO =====================');                 let setting = {};                 setting[`repeating_${attackcategory}_template`] = "DnD35Attack";             }             setAttrs(setting);         });     }); }); Any advice/suggestions appreciated! Thanks!
1516377636
Jakob
Sheet Author
API Scripter
Here's one thing that I'm noticing: in your event string, you use attrs.map(str => `change:${str}`).join(' ') but for repeating events, you would need a colon instead an underscore after ${attackcategory}. You do this correctly in the non-templated version.
Ah, so on top of anything else I messed up Roll20 syntax. D'oh! Thanks for the second set of eyes, Jakob. Unfortunately, even now that error is corrected, the script continues to fail with no error or logging. :-(