
I've been muddling along reasonably well on my own, but now completely stuck at the final hurdle so any help greatly appreciated!! I have a number of sheetworkers rolling dice and passing information to the rolltemplate very happily. Here's one that works exactly as required: const PCroll = [ 'talking', 'physical', 'fighting', 'shooting' ]; PCroll.forEach(button => { on(`clicked:${button}`, () => { getAttrs(['[`${button}used`]', 'ones', 'twos', 'threes', 'fours', 'fives', 'sixes', 'sevens', 'eights', 'nines', 'tens'], v => { startRoll(`&{template:PC} {{name=@{character_name}}} {{type=[[0]]}} {{action=rolls ${button}}} {{Roll=[[[[@{${button}}]]d6]]}} {{ones=[[0]]}} {{twos=[[0]]}} {{threes=[[0]]}} {{fours=[[0]]}} {{fives=[[0]]}} {{sixes=[[0]]}} {{sevens=[[0]]}} {{eights=[[0]]}} {{nines=[[0]]}} {{tens=[[0]]}}`, (PCroll) => { const dice = PCroll.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( PCroll.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); }); }); }); }); What happens is the player clicks one of those four buttons (talking, physical, ...) to perform the roll. The worker rolls a number of d6 equal to the stat that corresponds to the button clicked. Then it records the number of each value rolled and adds these counts to attributes on the sheet (dummy1, dumy2, ...). It also adds each of these values to the count of those values previously rolled and stored on the sheet (ones, twos, ...) and sends them to the rolltemplate ({{ones=[[0]]}}, {{twos=[[0]]}}, ...). This is so that the rolltemplate's output can display the new totals for each value. E.g. If I have a 2 and a 4 in the bank and I roll 'talking' with a stat of 3 scoring two 1s and a 2 then the output will show I now have two 1s, two 2s and a 4. I now need to adapt another worker to this model, but the problem is that it was set up for repeating sections so it's structured rather differently (I had a LOT of help with it and don't fully understand it!). Here it is just using the default rolltemplate: //Utility function from the K-scaffold. Parses out the section name, row id, and attribute name from an event's triggerName or sourceAttribute. const parseTriggerName = function(string){ let match = string.replace(/^clicked:/,'').match(/(?:(repeating_[^_]+)_([^_]+)_)?(.+)/); match.shift(); return match; }; on('clicked:repeating_belongings:gearroll',(event)=>{ //Get our row information; we may not need all of this, but showing how you'd get all of it. //section = `repeating_belongings`; rowID = the rowID; buttonName = gearroll const [section,rowID,buttonName] = parseTriggerName(event.triggerName); //The callback for this getAttrs is going to be async so that we can use the async/await pattern with startRoll getAttrs([`repeating_belongings_${rowID}_gearquality`],async (attributes)=>{ //Convert the value to a number attributes[`repeating_belongings_${rowID}_gearquality`] = +attributes[`repeating_belongings_${rowID}_gearquality`]; //array to use to lookup how many dice of what size to roll const diceLookup = [ {size:4,multiplier:1}, {size:6,multiplier:1}, {size:6,multiplier:2}, {size:8,multiplier:1}, {size:8,multiplier:2}, ]; //Extract the appropriate details const dieDetails = diceLookup[attributes[`repeating_belongings_${rowID}_gearquality`] - 1]; if(!dieDetails) return; //If there are no details, then don't send a message //Construct our message. The roll has to be in a roll template for CRP to work. const message = `&{template:default} {{name=@{character_name}}} {{action=rolls @{repeating_belongings_${rowID}_gear}}} {{Roll=[[[[(1 - @{repeating_belongings_${rowID}_gearused}) * ${dieDetails.multiplier}]]d${dieDetails.size}]]}}`; //Send the roll, and wait for the results to come back const result = await startRoll(message); const dice = result.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; finishRoll(result.rollId);//We aren't doing any manipulation of the roll, so we can just finish it right away setAttrs({//Set your attributes [`repeating_belongings_${rowID}_gearused`]: 1, dummy1: roll1s, dummy2: roll2s, dummy3: roll3s, dummy4: roll4s, dummy5: roll5s, dummy6: roll6s, dummy7: roll7s, dummy8: roll8s, dummy9: roll9s, dummy10: roll10s }); }); }); So this one rolls a stat corresponding to the button in the repeating section and records the count of each value rolled. What I need is for finishRoll to calculate the sums in the first worker (ones: roll1s + (+v.ones || 0), etc.), but all attempts at mirroring the first worker have failed. Can anybody please advise?