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

Take highest or lowest dice based on an input vlaue

I am trying to write a formula that rolls a certain number of dice, then takes the high or low based on the value input. So, say you are prompted for a number of Shifts .  The absolute value of this number of shifts should be added to three.  Then roll that number of d6 and keep the highest  values if the shift is above 0, or the lowest  values if the shift is below 0. Thus, if a player inputs a -2, the roll should resolve to: 5d6kl3 if the player inputs a 4, the roll should ultimately resolve to: 7d6kh3 It seems like there should be a fairly straight-forward way to do this, but it has eluded me thus far. Getting the total number of dice is simple: ([[abs(?{Dice}) + 3]])d6 Getting the kl and kh parts to work has been very challenging.  Thus far I managed to put somethings together so that by using tables named [0] and [1] that contain only the values kl and kh respectively, this horrible formula will return that text: [[1t[[[{1d1, 0d1 + [[{0d1, 0d1+?{Dice}}kh1]]}kl1]]]]] I've tried compositing those parts together, but it doesn't resolve correctly: ([[abs(?{Dice}) + 3]])d6([[1t[[[{1d1, 0d1 + [[{0d1, 0d1+?{Dice}}kh1]]}kl1]]]]])(3) It doesn't seem to parse this correctly, and it just takes the number of dice and returns that result. With the number of things the Dice Roller can do, this seems like one where I am just missing something obvious.
1595998758

Edited 1595999155
Oosh
Sheet Author
API Scripter
A second Query for whether Shift is positive or negative would simplify it enormously. But it's an extra Query. How wide a variety of values is Shift likely to take? A drop down Query or a Chat Menu with the possible values is an option, linked to macros which are hard-coded for that value. There's not really a straight forward way to do this that I can think of - you're trying to combine a text operator and integer in the same Query result, which is difficult to do without the API and generally requires some pretty hacky solutions as you've tried above. You do have a Pro subscription - API would be the cleanest solution. If the second Query doesn't bother you, then it is a pretty simple macro: /roll [[abs(?{Dice}) + 3]]d6?{Positive or negative?|Positive,kh3|Negative,kl3} I would leave the abs function in there as you had it, in case the player enters a negative value, despite the second Query.
I'd like to try to avoid using a query at all, as sometimes these rolls should be automatic, based on running values. I may have to use the API, but I was really hoping to avoid it.  With all the power the dice parser has, this seems like an odd limitation.
1596030967
GiGs
Pro
Sheet Author
API Scripter
The dice parser has a lot of limitations. It cant do conditional tests, for example, which this requires (being able to test whether to take higher or lower dice, for example).
1596031642
Oosh
Sheet Author
API Scripter
Zane T. said: I'd like to try to avoid using a query at all, as sometimes these rolls should be automatic, based on running values. I may have to use the API, but I was really hoping to avoid it.  With all the power the dice parser has, this seems like an odd limitation. You 100% have to use API. A macro can't be triggered, or read past values. You have absolutely no hope of achieving this without at least one Query with standard macros... but I admire you efforts :)
1596033504
Kraynic
Pro
Sheet Author
Hmm, how about this. Write a macro that you would use if Shifts is above 0.  Write another macro that you would use when Shifts is below 0.  Write a macro that will print out the current Shifts value and a pair of chat menu buttons (one for each of the 2 previously written macros).  Then, when you run the macro to print out the Shifts value, you just click the button indicated by the Shifts value to run your main macro.  That would take 2 clicks, but wouldn't require the api.  I don't know if you are using tokens, but if there is a free bubble/bar, it seems to me that players could be altering their number of dice or keeping track of Shift there.  That would keep an attribute updated on the sheet and maybe allow you to eliminate a query. Or maybe I am misunderstanding how your situation and setting up that way isn't possible.
So this super simple formatted string gives me exactly what I need.  Is there a simplistic way to call it from a character sheet or macro button? function formatRoll(shifts, modifier) { return `${Math.abs(shifts) + 3}d6${shifts < 0 ? 'kl' : 'kh'}3${modifier < 0 '-' : '+'}${Math.abs(modifier)}`; }
1596045334

Edited 1596045346
GiGs
Pro
Sheet Author
API Scripter
Here's a very quick and direty script that gives you the roll you need // !highorlow :name of roll :number of shifts :modifier // !highorlow :This is a Roll :3 :-2 on('ready',function(){ on('chat:message',function(msg){ if(msg.type=='api' && msg.content.toLowerCase().startsWith('!highorlow') ){ const args = msg.content.split(/\s+:/); const title = args[1]; const shifts = parseInt(args[2]) || 0; const modifier = parseInt(args[3]) || 0; const numberDice = 3 + Math.abs(shifts); const direction = shifts > 0 ? 'kh3' : (shifts < 0 ? 'kl3' : '' ); const diceroll = `${numberDice}d6${direction}${modifier > 0 ? `+${modifier}` : (modifier < 0 ? modifier : '' )}`; const output = `&{template:default} {{name=${title}}} {{shifts=${shifts}}} {{modifier=${modifier}}} {{result=[[${diceroll}]]}}`; sendChat('highorlow', output); } }); }); Since there's no error checking and players will enter incorrect values causing the snadbox to crash, I recommend using a script with text like this: !highorlow :?{Title of roll|enter title here} :?{shifts|0|1|2|3|-1|-2|-3} :?{modifier|0|1|2|3|-1|-2|-3} For the shifts and modifier query, you want to account for every possible number that might apply. You could also add some error checking to let people enter whatever they want and handle the inevitable errors.