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!