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 .
×

Conditional Output for Rolls without API

Hi everyone, I'm a longtime user of Roll20 but have only just started working on custom character sheets. Specifically, I'm designing one for a homebrew system I made where the roll system is concerned with where a given d100 result lands in four specific bands (critical, normal, marginal, and failure). I've gotten the basics down and have it so that the default roll template will post the result with the range bands detailed. I'm looking to offload the difficulty of determining the specific band onto the computer if I can, but I'd prefer to not use the Roll20 API for purposes of accessibility. I'm familiar with HTML and CSS, though it's been a while since I've touched a compiler, and my JavaScript knowledge is severely lacking. I've read the threads about reusing rolls, but I can't find a way to implement conditionals within a roll button. I tried using an action button to pass a result to a script, but couldn't get it to work. Is there something I'm missing, or do I need to dip into the API? Thanks, -John
1604606881

Edited 1604606941
David M.
Pro
API Scripter
Conditionals without api is limited to non-existent. The Powercards script would be the no-personal-javascript-knowledge-required api solution, as it would allow "roll>X, do Y" types of conditional output. Without api, if your success ranges are relatively consistent, or there are only a few variations, rollable tables with 100 equally weighted entries each containing the roll number and the success level would work. Then call it with [[ 1d[TableName] ]]. A bit of setup, though, so if you wanted to change things on the fly it would not work well. 
Hmm, unfortunate. The ranges change depending on the roll. Looks like I'll be dipping into the API then. Thanks!
1604607994

Edited 1604608186
David M.
Pro
API Scripter
Bummer. Ok, I'd probably check out powercards first before messing with writing your own script, unless you just want to. The custom script wouldn't be too difficult, though, so if you don't like powercards for whatever reason, there are plenty of folks here that could help you out.
I'll take a look at it. If nothing else, it might work as a nice basis for what I eventually write.
1604614755
Finderski
Pro
Sheet Author
Compendium Curator
Can you describe what you're trying to accomplish? I mean with dice roll examples and what the output should look like? There may be a way to do that with the roll template itself...
1604624107

Edited 1604663807
David M.
Pro
API Scripter
Here's a simple script that might get help get you started if you want to write your own. You'd still need to add modifiers into the rolls. Now that I think about it, I should have just added an inline roll parser so mods and different die rolls would be handled, derp. Threw it together quickly, so nothing fancy, with limited error handling (or testing, really). Syntax is: !d100 checkName marginalScore normalScore criticalScore  Note: checkName currently can't contain any spaces e.g. !d100 Stealth 20 40 60  Here's the code: on('ready',function() {     on('chat:message',function(msg){         if(msg.type==='api' && msg.content.indexOf('!d100')===0) {             try {                 const scriptName = 'd100';                 let result;                 let displayRolls                 let check, marginal, normal, critical;                                  who = getObj('player',msg.playerid).get('_displayname');                 let args = msg.content.split(/\s+/);                 args.shift();                                  if (args.length < 4) {                     sendChat(scriptName,`/w "${who}" `+ 'Error. Not enough arguments. Format is \"!d100 checkName marginalScore normalScore criticalScore\"');                     return;                 } else {                     check = args[0];                     marginal = parseInt(args[1]);                     normal = parseInt(args[2]);                     critical = parseInt(args[3]);                     if (isNaN(marginal) || isNaN(normal) || isNaN(critical)) {                         sendChat(scriptName,`/w "${who}" `+ 'Error. Non-numeric limit detected');                         return;                     }                 }                                  let r = randomInteger(100);                                  if (r < marginal) {                     result = 'Failure';                 } else if (r < normal) {                     result = 'Marginal Success';                 } else if (r < critical) {                     result = 'Normal Success';                 } else {                     result = 'Critical Success';                 }                                  let output = `&{template:default} {{name=${check} check}} {{Roll=[[${r}]]}} {{Result=${result}}}`;                 sendChat('d100', output);             }             catch(err) {               sendChat('',`/w "${who}" `+ 'Error: ' + err.message);             }         }     }); }); Here's some sample output for the Stealth check example given above (20/40/60)
1604678297
Andreas J.
Forum Champion
Sheet Author
Translator
If the d100 roll have no modifiers, then you should be able to get pretty close with just creating a roll template that shows different sections depending on the roll result. Read about the Helper Functions: <a href="https://wiki.roll20.net/Roll_Templates#Helper_Functions" rel="nofollow">https://wiki.roll20.net/Roll_Templates#Helper_Functions</a>
Thank you all for your help. There are some other things that I'd like to do with the sheet that require the API, I think, so ultimately I will have to use it, but I hadn't seen the helper functions yet (I had mistakenly thought the roll templates were all structure and no logic). Ultimately, what I'm wanting the roll to do is roll a d100 and check the result against three separate and discreet value ranges. If the value falls between one of the ranges, I want it to say which range. If the result doesn't fall between any of them, then it comes up a failure. If the roll could also check what the difference is between the upper value of the range and the result, that would also be ideal. David's script seems ideal for that, and I'll likely use it in the API version of my sheet. If there's a way to do this through roll templates, that would be ideal. Said another way, if a player has a value of 1-4 for their crit range, 5-37 for their normal range, and 38-43 for their marginal range, I'd like the roll to determine where result is, show the result, and say which range (crit, normal, marginal, failure), and by how much its in the range. I'll be looking through the roll templates section now to see if that's viable. Thanks again, everyone.