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

Simple StartRoll with Reroll in template

1666118883
Paul V.
Pro
Sheet Author
Compendium Curator
Starting my journey with startRoll I'm attempting to get a reroll chat menu to work in the template. The idea is to calculate reroll all the dice that failed to get a 6. I'm using the results totalminus the number of dice i rolled to get the number of dice i needed to reroll, here is the code snippet, i'm obviously dfoing something wrong... <button type="action" name="act_test">Click me</button> <rolltemplate class="sheet-rolltemplate-test"> <div class="sheet-template-container"> <h1>{{name}}</h1> <div class="sheet-results"> <h4>Result = {{roll1}}</h4> <h4>[Reroll](`/r {{computed::roll1}}d6)</h4> </div> </div> </rolltemplate> <script type="text/worker"> on('clicked:test', async (info) => { const results = await startRoll("&{template:test} {{name=Test}} {{roll1=[[6d6>6]]}}"); const total = results.results.roll1.result const computed = 6-total; finishRoll( results.rollId, { roll1: computed, } ); }); </script>
1666126469
Paul V.
Pro
Sheet Author
Compendium Curator
Oh i forgot to post the error I’m getting There was an error with your formula. Please try again.
1666445097
Paul V.
Pro
Sheet Author
Compendium Curator
fixed it after some experimentation - using OnyxRing's code for setting attribs and saving roll info in attribs to use for the next roll/reroll <!-- The visible and draggable button for the macro bar --> <button type="roll" name="roll_test" value="@{test_action}">test</button> <!-- The invisible button allowing the use of custom roll parsing --> <button type="action" name="act_test-action" class="hidden"></button> <button type="action" name="act_test-reroll" class="hidden"></button> <!-- The invisible field for the attribute which contains the ability call --> <input type="hidden" name="attr_test_action" value=""> <input type="hidden" name="attr_test_successes" value=""> <input type="hidden" name="attr_test_dicerolled" value=""> <input type="hidden" name="attr_test_ones" value=""> <rolltemplate class="sheet-rolltemplate-test"> <div class="sheet-template-container"> <h1>{{name}}</h1> <div class="sheet-results"> <h4>Successes = {{computed::roll1}}</h4> <h4>[Push]({{reroll}})</h4> </div> </div> </rolltemplate> <rolltemplate class="sheet-rolltemplate-testreroll"> <div class="sheet-template-container"> <h1>{{name}}</h1> <div class="sheet-results"> <h4>Successes = {{computed::roll1}} Prior={{prior}} Ones={{ones}}</h4> </div> </div> </rolltemplate> <script type="text/worker"> on("sheet:opened change:character_name", function(eventInfo) { getAttrs(["character_name", "test_action","test_reroll"], function(v) { var attrsToChange = {}; attrsToChange["test_action"] = "%{" + v["character_name"] + "|test-action}"; setAttrs(attrsToChange); }); }); on('clicked:test-action', async (info) => { const values = await getAttrsAsync(['strength','endure','character_name']); const stat = +parseInt(values.strength) || 0; const skill = +parseInt(values.endure) || 0; const charname = values.character_name || ""; const statskill = stat+skill; const results = await startRoll("&{template:test} {{name=Test}} {{roll1=[[[["+statskill+"+?{Bonus}]]d6>6]]}} {{reroll=~"+charname+"|test-reroll}}"); const successes = results.results.roll1.result; const dicerolled= results.results.roll1.dice.length; const thedice= results.results.roll1.dice; const ones= thedice.filter(element => element < 2); const totalofones = ones.length; const computed = successes; var attrsToChange = {}; attrsToChange["test_successes"] = successes; attrsToChange["test_dicerolled"] = dicerolled; attrsToChange["test_ones"] = totalofones; setAttrs(attrsToChange); finishRoll( results.rollId, { roll1: computed, } ); }); on('clicked:test-reroll', async (info) => { const values = await getAttrsAsync(['test_dicerolled','test_successes','test_ones']); const priorsuccesses = +parseInt(values.test_successes) || 0; const dicerolled = +parseInt(values.test_dicerolled) || 0; const ones = +parseInt(values.test_ones) || 0; const results = await startRoll("&{template:testreroll} {{name=Test}} {{roll1=[["+(dicerolled-priorsuccesses-ones)+"d6>6]]}}{{prior="+priorsuccesses+"}}{{ones="+ones+"}}"); const successes = results.results.roll1.result; const computed = successes+priorsuccesses; finishRoll( results.rollId, { roll1: computed, } ); });
1666510552
.Hell
Sheet Author
Seems like you forgot the second ` in <h4>[Reroll](`/r {{computed::roll1}}d6)</h4>
1666535241
Paul V.
Pro
Sheet Author
Compendium Curator
Hi for Chat Menus you don't need the second ` here is the example  that roll20 gives [embedded roll](`/r d20+4)