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
This post has been closed. You can still view previous posts, but you can't post any new replies.

New dice rounding options

I am just getting started with roll20 and am trying to get a macro that works out degrees of success/failure for the 40k role playing games (I know I can just not round it but I'd prefer it to be neater). From what I can tell it's not possible to do exactly because it will round either the degrees of success or failure wrongly. This would be fixable with commands that rounded towards zero (for DH, RT and DW) and away from zero for the newer games. I apologise if this is doable another way, I did some research and couldn't find anything.
1399344934
Gauss
Forum Champion
We already have ceiling and floor functions. Using the floor function and adding 0.5 to any number you can replicate rounding (less than 0.5 rounds down, 0.5 rounds up). Example: /r floor(2d6/2+0.5) = floor(7/2+0.5) = floor(3.5+0.5) = floor (4) = 4
1399363520

Edited 1399363598
Lithl
Pro
Sheet Author
API Scripter
While floor is all you should need for the 40k games (I don't even think you need to add 0.5 to achieve the round function in those systems; AFAIK it's always round down), the two rounding functions don't serve every purpose we might need. floor(x) provides "round towards negative infinity" ceil(x) provides "round towards positive infinity" floor(x+0.5) and ceil(x-0.5) provide "round to nearest" We have no means to perform "round towards zero" (also called truncate ) We have no means to perform "round away from zero" (or alternatively, "round towards infinity") The last two are relevant when negative numbers become involved, as according to one of the issues up on the character sheet Git repo, "round towards zero" is useful for GURPS. The last two rounding modes can be implemented if we had access to sign and abs . (Where sign is the signum function, and abs is the absolute value function.) round towards zero: sign(x) * floor(abs(x)) or alternatively, -sign(x) * ceil(-abs(x)) round towards infinity: sign(x) * ceil(abs(x)) or alternatively, -sign(x) * floor(-abs(x))
1399370742

Edited 1399370825
I am already aware of ceil and floor and am currently using them but they don't work properly. When it comes to degrees of failure negative numbers are involved which is why it doesn't work. This is the macro I am currently using /r ceil((?{Characteristic|1} + ?{Modifier|0}- 1d100)/10). This gives me degrees of success in the Black Crusade version of Degrees of Success where a pass is one and each additional 10 is an additional one but it makes degrees of failure off by 1 so it makes 1 degree of failure 0 degrees. If I switch it to floor it makes Degrees of success work in Dark Heresy but adds one to the degrees of failure. Hope that clears up why I am asking for it.
1399372879
Lithl
Pro
Sheet Author
API Scripter
Neil, they work exactly properly, they just aren't the functions you're actually wanting. You want access to a truncate function.
1399374358

Edited 1399374507
Yes I know they do what they are meant to do. When I said they don't work properly it was in reference to you telling me that they could be used for the 40k rp lines. Since you told me that was all I needed I was pointing out that it doesn't do it correctly. It should have been obvious that I knew how ceil and floor worked as I am already using them and I started this thread to ask specifically for new rounding functions to do this task.
1399400451
Lithl
Pro
Sheet Author
API Scripter
Sorry, I think I misinterpreted your original post. If you're trying to get both degrees of success and failure at the same time, that would certainly be a problem.
I think I may have a suggestion for you, but can't find 40k rules online (and don't play it myself). Could you explicitly lay out the mathmatical relation you are looking for?
1399412894

Edited 1399510605
I am using the Black Crusade and later version of this which changed in that it made a pass or fail 1 degree of success/failure. Dark Heresy to Deathwatch did it slightly differently by having a pass or fail being 0 degrees of success/failure. I am just making this clarification for anyone who may be familiar with the Dark Heresy version and is confused to why I have a base pass as 1. The way it works is that you have a target value determined by your characteristic and then with various modifiers that change this target number making it higher or lower. Lets say for a simple example that the target value is 50. You then roll a d100 and want to get lower than 50. For every 10 points under it you get under it you get 1 degree of success and for every 10 points over it you get 1 degree of failure. Here is a table representing the DoS/DoF for that target number. 91-100 - 5 degree of failure 81-90 - 4 degree of failure 71-80 - 3 degree of failure 61-70 - 2 degree of failure 51-60 - 1 degree of failure 41-50 -1 degree of success 31-40 - 2 degree of success 21-30 - 3 degree of success 11-20 - 4 degree of success 1-10 - 5 degree of success What I want is for the output to be positive integers for degrees of success of negative ones for degrees of failure. Currently it can accurately do one or the other with ceil or floor but it cannot do both. I have picked it to do degrees of success in the macro I have been using which is this /r ceil((?{Characteristic|1} + ?{Modifier|0}- 1d100)/10) as they tend to be more relevant but preferably it would do both correctly. Thanks for the help, Neil EDIT - I realize that I have made an error in my macro so it won't round correctly. To fix that I will just add 0.1 to the roll. I just wish I didn't need to fix a million character macros
Ugh. I'm afraid I was mistaken, and I can't come up with a round toward infinity function for you. If you wanted to round toward zero, I could help you using currently-available macros. Also, Brian, sign and abs will only help if someone is also a mentor and can use the same die result twice in one line of API code, since we can't use it twice in a macro (unless I'm mistaken, and *please* tell me I am).
1399577688

Edited 1399579169
Thanks anyway. The way I have it now is fine for the most part, we will just need to remember to adjust DoF when we are playing. I would still suggest a round towards and away from 0 function be added in a similar vein to ceil and floor. It just gives more flexibility that could be useful in other games as well. EDIT - is this something I could do as a mentor with API scripts? If so I might upgrade if we start playing using roll20 regularly.
1399579647

Edited 1399579807
Lithl
Pro
Sheet Author
API Scripter
Neil, with an API script you'd have access to the full JavaScript Math library, among other things. Kikanaide, you're right that you can't re-used a die result in a macro, but some uses of rounding don't need that; they need to perform calculations on attributes and/or query values, instead, so it would work fine.
Ah, that's a good point. My PF rounding being an example of attribute-based needs, where it makes sense.
Hi Neil, Try taking your "ceil" formula and putting it in in the following formula as "x": round((x-0.5)*1.01) You'll have both a round and ceil, but it should work in standard macros and not require the API. Let me know if that works.
It's just saying error. I don't think I have round as a command. Thanks for trying anyway. This is the formula that I used. /r round(((ceil((?{Characteristic|1} + ?{Modifier|0}- 1d100+0.1)/10))-0.5)*1.01)
1400731588
Lithl
Pro
Sheet Author
API Scripter
No, there is no round function in the dice roller. However, floor(x + 0.5) or ceil(x - 0.5) accomplishes the same task the round would do.
My game uses Fudge dice (which often roll negative numbers) and I would dearly love to see a feature that rounds towards or away from zero.
1400781763

Edited 1400783977
Ok this works /r floor((((ceil((?{Characteristic|1} + ?{Modifier|0}- 1d100+0.1)/10))-0.5)*1.01) + 0.5) I've tested it a bunch and as far as I can see it behaves exactly as it should. I'll post back if I find any errors. Thanks for the help guys. I'm not sure if I can cut some of that out or not? I would still recommend the inclusion of the new rounding options as you may notice that this way is slightly convoluted as a way to get something that could be much simpler. Should I post this somewhere else so people who play 40k games can see it? Now to go and edit 18 character sheets with 3 macros each :( Thanks again. EDIT: To do the Dark Heresy/WFRP version of this I just changed the multiplication from 1.01 to 0.99 but while that works it can't tell that difference between a basic pass or fail (they just both show 0) and I doubt you could do anything about that.
Sorry, round must only be on the dev server. Glad you got it working. I'd imagine round will make it's way to production with data delve... For the round to zero games, honestly you're likely better off subtracting one mentally from both number of successes and failed.... There's no way you'll be able to differentiate otherwise.
Only thing you could do (and it's not really better) would be to distribute out the last few terms and delete a few unnecessary parenthesis. You could use something like: /r floor(ceil((?{Characteristic|1} + ?{Modifier|0}- 1d100+0.1)/10)*1.01 - 0.005) At this point I'm guessing you've updated your stuff, though, so feel free to use what works. This one is mathematically equivalent, though, and somewhat cleaner. You need to subtract a tiny amount to make what used to be 0 negative so floor will catch it, and you need to multiply because you want +1, etc. to be immune to the subtraction.