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

Inline Minimum Roll Sum

So I thought I figured out how to create a minimum roll via an inline "trick", but it doesn't work like I want it to. Let's say I'm using a formula like: [[((@{dicenum}d@{dietype})/2)+some_mod]] but I don't want the roll to be any less than 0. If all I want is a static number (e.g. not rolled), the "floor" function works great... but this (among other things I've tried: such as ,1d1} kh1) doesn't seem to work. Any thoughts?
1539692778

Edited 1539692827
GiGs
Pro
Sheet Author
API Scripter
What do you have a /2 there for? That's going to lead to fractional values. Try something like this [[{round((@{dicenum}d@{dietype})/2)+some_mod,0d0}kh1]] Test it in an ability first, before putting it in your character sheet code, to make sure it works. Make sure there are no spaces, especially between } and kh1
1539706941
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
Here is an option using a sheet worker function. The max value in this case is 13 whereas the min is -99. I believe it would be possible to reverse this at get a min. var fCheck = (Math.min(13, Math.max(-99, fBase + fMod))); ex. var fCheck = (Math.max(-99, Math.min(13, fBase + fMod))); hope this helps...
1539714601

Edited 1539714824
Ares
Pro
GG... in some of my calcs, I actually use fractional values. For the calcs I don't want decimals for, I just use the floor function (vs round... since most of my calcs round down, not up ;-) ). Thx for your observation tho. (edit -- your suggestion, GG, & Scott's, are both really good ideas... I think I'll have a good place to use 'em both in my sheet. Thx so much!!) Scott.... THANK YOU!! As html isn't really my forte, I didn't know you could use variable math in the sheet code!! That helps a TON!!! I can see that being useful in MANY places within my current sheet project, & others!!
1539714923
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Note that what Scott S. posted would be done in a sheetworker (javascript appended to the sheet code), not in the html of the sheet itself.
Ah... that makes more sense, lol. The "sheetworker" line threw me off. Thanks for the clarification!!
1539719796
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
Here is the whole thing.... // Update Willpower, Fear on('change:intelligence change:willpower_points change:willpower_mod change:fear_check_points change:fear_check_mod', function (e) { updateWill(); }); // Updage Willpower, Fear -- Updated to reflect 'Rule of 14' for fright checks pg. 360 function updateWill() { console.log('********* updateWill *********'); getAttrs(['intelligence', 'intelligence_base', 'willpower_points', 'willpower_mod', 'fear_check_points', 'fear_check_mod'], function(v) { var wBase = (modCascade ? +v.intelligence : +v.intelligence_base) + ((+v.willpower_points || 0) / 5 | 0); var wMod = +v.willpower_mod || 0; var fBase = wBase + (modCascade ? +wMod : 0) + ((+v.fear_check_points || 0) / 2 | 0); var fMod = +v.fear_check_mod || 0; var fCheck = (Math.min(13, Math.max(-99, fBase + fMod))); setAttrs({ willpower_base: wBase, willpower: wBase + wMod, fear_check_base: fBase, fear_check: fCheck }); }); }
1539720068
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
There's a lot of fluff in there because of the ruleset I am using. But the basic idea is the getAttrs pulls the value from the Attr when it is told to by the "on change" function. Once the Get function has the value it turns it into a number does calculations against it then sends it back out the sheet via setAttrs. Essentially a 3 step process Listen to be told to do command, do command, then send back to sheet.
Thx for the code snippet!!
1539721222

Edited 1539723585
Ares
Pro
One final thought.... I will tinker with your code, Scott, but could you (or someone) help me solve the inline min. value that GG suggested earlier. I've tried using every combination I can think of, (inc. those suggested on&nbsp; <a href="https://wiki.roll20.net/Dice_Reference" rel="nofollow">https://wiki.roll20.net/Dice_Reference</a> &nbsp;), without success... unless this is something that MUST be done via worksheet. Specifically, my inline code looks like this:&nbsp; [[@{add_damage}-@{tgt_def}]] I've tried every combination I can think of (inc. crazy ones, lol) to make the result no lower than 0, when tested... all without success. e.g. [[{round(@{add_damage}-@{tgt_def}),0d0}kh1]] [[{floor(@{add_damage}-@{tgt_def}),0d0}kh1]] [[{@{add_damage}-@{tgt_def},0d0}kh1]] [[@{add_damage}-@{tgt_def}kh1]] [[@{add_damage}-@{tgt_def}|0]] etc.... Would this suggest that achieving an inline min. of 0 not possible without using a sheetworker? (edit, as Kraynic pointed out, I screwed up the brackets while typing what I'd tried. It's fixed now)
1539722567

Edited 1539722752
Kraynic
Pro
Sheet Author
I might be wrong, but it looks like you have missed closing the first calculation.&nbsp; Maybe it should look like this? [[{round(@{add_damage}-@{tgt_def}),0d0}kh1]] After posting this I realized your first 2 examples have a ) instead of } after add_damage.&nbsp; If that wasn't a typo in the post, that probably confused things a little.
1539728576
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Proelium Ex Deus said: One final thought.... I will tinker with your code, Scott, but could you (or someone) help me solve the inline min. value that GG suggested earlier. I've tried using every combination I can think of, (inc. those suggested on&nbsp; <a href="https://wiki.roll20.net/Dice_Reference" rel="nofollow">https://wiki.roll20.net/Dice_Reference</a> &nbsp;), without success... unless this is something that MUST be done via worksheet. Specifically, my inline code looks like this:&nbsp; [[@{add_damage}-@{tgt_def}]] I've tried every combination I can think of (inc. crazy ones, lol) to make the result no lower than 0, when tested... all without success. e.g. [[{round(@{add_damage}-@{tgt_def}),0d0}kh1]] [[{floor(@{add_damage}-@{tgt_def}),0d0}kh1]] [[{@{add_damage}-@{tgt_def},0d0}kh1]] [[@{add_damage}-@{tgt_def}kh1]] [[@{add_damage}-@{tgt_def}|0]] etc.... Would this suggest that achieving an inline min. of 0 not possible without using a sheetworker? (edit, as Kraynic pointed out, I screwed up the brackets while typing what I'd tried. It's fixed now) so, this is partially going to depend on what the possible values of add_damage and tgt_def are. You can't mix rolls and raw numbers in grouped rolls (the {...,...} part of the syntax. So, if add_damage and tgt_def are always going to be raw numbers (e.g. 2, 3, 4, floor(5/2)), then you can't use 0d0 in the second argument. Since I think this is what they are, here's what it should look like: [[{round(@{add_damage}-@{tgt_def}),0}kh1]] I've left the round calcing on the add_damage - the tgt_def because not sure if that was intended, but unless there's some division/multiplication in those two attributes, you don't need the round(). Here's the code that I used to test this: [[{floor(5/2)-?{what|1|5},0}kh1]]
1539731049

Edited 1539731166
Ares
Pro
Scott C. said: So, if add_damage and tgt_def are always going to be raw numbers (e.g. 2, 3, 4, floor(5/2)), then you can't use 0d0 in the second argument. Since I think this is what they are, here's what it should look like: [[{round(@{add_damage}-@{tgt_def}),0}kh1]] You nailed it sir. Thanks for everyone's time &amp; comments on this. This topic may now be closed. (edit: I REALLY suck at overlooking brackets, btw. It seems like I'm forever hunting down rogue or mistyped brackets, so thx for bearing with me through this)