
I have a dice-rolling sheetworker that I'd like to generalise across multiple buttons rather than have 12 slightly different copies of it (I also have a lot of other sheetworkers that will benefit to the same extent). I have it all working except that I need the setAttrs to set an attribute that corresponds to the specific button clicked and I don't know the syntax. Here's the whole sheetworker: const NPC1talking = [ 'NPC1talking' ]; NPC1talking.forEach(button => { on(`clicked:${button}`, () => { getAttrs(['NPC1talking'], v=> { startRoll(`&{template:default} {{name=${button}}} {{Roll=[[[[@{${button}}]]d6]]}}`, (NPC1talking) => { const dice = NPC1talking.results.Roll.dice //This will be an array of the values rolled on all the dice const total1s = dice.filter(d => d === 1).length; const total2s = dice.filter(d => d === 2).length; const total3s = dice.filter(d => d === 3).length; const total4s = dice.filter(d => d === 4).length; const total5s = dice.filter(d => d === 5).length; const total6s = dice.filter(d => d === 6).length; const total7s = dice.filter(d => d === 7).length; const total8s = dice.filter(d => d === 8).length; const total9s = dice.filter(d => d === 9).length; const total10s = dice.filter(d => d === 10).length; finishRoll( NPC1talking.rollId, // this is where you save the computed values into something that can be passed to rolltemplates. { } ); setAttrs({ NPC1talkingused: 1, dummy1: total1s, dummy2: total2s, dummy3: total3s, dummy4: total4s, dummy5: total5s, dummy6: total6s, dummy7: total7s, dummy8: total8s, dummy9: total9s, dummy10: total10s, }); }); }); }); }); This works exactly as I need it to for the NPC1talking button, but I want to generalise it for all 12 NPCs. I've done this within the roller itself (see name= and roll=), but I also need to do it for NPC1talkingused in the setAttrs. That is, once the sheetworker has been set up for all 12 buttons ( NPC1talking , NPC2talking , etc) I need setAttrs to set a specific attribute to 1 and that attribute has the same name as the button clicked but with 'used' added on the end. I.e. If the NPC7talking button is clicked, then after the roll is computed the NPC7talkingused attribute needs to be set to 1 with all the other NPC#talkingused attributes being left alone. What would the syntax for that be? Or is it not doable?