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

Dice calculation to inform rolltemplate

I have the following sheet worker: const NPCp = [   'NPC1physical',   'NPC2physical',   'NPC3physical',   'NPC4physical',   'NPC5physical',   'NPC6physical',   'NPC7physical',   'NPC8physical',   'NPC9physical',   'NPC10physical',   'NPC11physical',   'NPC12physical' ]; NPCp.forEach(button => {   on(`clicked:${button}`, () => {     getAttrs(['[`${button}used`]', 'ones', 'twos', 'threes', 'fours', 'fives', 'sixes', 'sevens', 'eights', 'nines', 'tens'], v => {       startRoll(`&{template:NPC} {{name=@{actor}}} {{action=Physical}} {{Roll=[[[[@{${button}}]]d10]]}}`, (NPCp) => {         const dice = NPCp.results.Roll.dice //This will be an array of the values rolled on all the dice         const setObj = {[`${button}used`]: 1};         setObj.dummy1 = dice.filter(d => d === 1).length;         setObj.dummy2 = dice.filter(d => d === 2).length;         setObj.dummy3 = dice.filter(d => d === 3).length;         setObj.dummy4 = dice.filter(d => d === 4).length;         setObj.dummy5 = dice.filter(d => d === 5).length;         setObj.dummy6 = dice.filter(d => d === 6).length;         setObj.dummy7 = dice.filter(d => d === 7).length;         setObj.dummy8 = dice.filter(d => d === 8).length;         setObj.dummy9 = dice.filter(d => d === 9).length;         setObj.dummy10 = dice.filter(d => d === 10).length;         finishRoll(           NPCp.rollId, // this is where you save the computed values into something that can be passed to rolltemplates.           {           }         );         setAttrs(setObj);       });     });   }); }); When one of those 12 buttons is clicked (NPC1physical, NPC2physical, etc.) it performs a roll of xd10, where x is the stat value for the NPC in question. Then it sets the values of ten attributes: dummy1 is set to the number of 1s rolled, dummy 2 is set to the number of 2s rolled, etc. This much is working perfectly. What I'm now trying to figure out is how to sum the attribute @ones with the new value of @dummy1 in such a way that the total can be reported in the rolltemplate. Same for twos + dummy2, etc. In other words, how do I tell the rolltemplate the value of @ones added to the number of 1s rolled?
Figured it out, so FYI: const NPCp = [   'NPC1physical',   'NPC2physical',   'NPC3physical',   'NPC4physical',   'NPC5physical',   'NPC6physical',   'NPC7physical',   'NPC8physical',   'NPC9physical',   'NPC10physical',   'NPC11physical',   'NPC12physical' ]; NPCp.forEach(button => {   on(`clicked:${button}`, () => {     getAttrs(['[`${button}used`]', 'ones', 'twos', 'threes', 'fours', 'fives', 'sixes', 'sevens', 'eights', 'nines', 'tens'], v => {       startRoll(`&{template:NPC} {{name=@{actor}}} {{action=Physical}} {{Roll=[[[[@{${button}}]]d6]]}} {{ones=[[0]]}} {{twos=[[0]]}} {{threes=[[0]]}} {{fours=[[0]]}} {{fives=[[0]]}} {{sixes=[[0]]}} {{sevens=[[0]]}} {{eights=[[0]]}} {{nines=[[0]]}} {{tens=[[0]]}}`, (NPCp) => {         const dice = NPCp.results.Roll.dice //This will be an array of the values rolled on all the dice         const roll1s = dice.filter(d => d === 1).length;         const roll2s = dice.filter(d => d === 2).length;         const roll3s = dice.filter(d => d === 3).length;         const roll4s = dice.filter(d => d === 4).length;         const roll5s = dice.filter(d => d === 5).length;         const roll6s = dice.filter(d => d === 6).length;         const roll7s = dice.filter(d => d === 7).length;         const roll8s = dice.filter(d => d === 8).length;         const roll9s = dice.filter(d => d === 9).length;         const roll10s = dice.filter(d => d === 10).length;         const setObj = {[`${button}used`]: 1};         setObj.dummy1 = dice.filter(d => d === 1).length;         setObj.dummy2 = dice.filter(d => d === 2).length;         setObj.dummy3 = dice.filter(d => d === 3).length;         setObj.dummy4 = dice.filter(d => d === 4).length;         setObj.dummy5 = dice.filter(d => d === 5).length;         setObj.dummy6 = dice.filter(d => d === 6).length;         setObj.dummy7 = dice.filter(d => d === 7).length;         setObj.dummy8 = dice.filter(d => d === 8).length;         setObj.dummy9 = dice.filter(d => d === 9).length;         setObj.dummy10 = dice.filter(d => d === 10).length;         finishRoll(           NPCp.rollId, // this is where you save the computed values into something that can be passed to rolltemplates.           {               ones:   roll1s + (+v.ones || 0),               twos:   roll2s + (+v.twos || 0),               threes: roll3s + (+v.threes || 0),               fours:  roll4s + (+v.fours || 0),               fives:  roll5s + (+v.fives || 0),               sixes:  roll6s + (+v.sixes || 0),               sevens: roll7s + (+v.sevens || 0),               eights: roll8s + (+v.eights || 0),               nines:  roll9s + (+v.nines || 0),               tens:   roll10s + (+v.tens || 0)           }         );         setAttrs(setObj);       });     });   }); });