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

Inconsistency in division by zero handling makes complex macros difficult to implement

1480251795

Edited 1480252141
Detailed Description of the Problem Roll20 handles division by zero differently when you are using talktomyself and when you aren't using it. If you are using it, the output is NaN, which is useful for making complex macros, as it allows a conditional switch. However, if you aren't using talktomyself, the macro just doesn't come through for whatever reason, making some macros potentially much more difficult to implement. An explanation of what I mean: a macro using division by zero for a conditional switch can, for example, output "1" when a number ends with the digit "3", and "0" in all other cases. Steps to Reproduce the Problem As an example, here is a skill DC calculator for 4e which relies on division by zero to function: DC's at level ?{Level?|6}: [[[[floor(0.5*?{Level?|6}+8)]]+[[ceil(?{Level?|6}/20)-1]]]]/[[[[round(0.7*?{Level?|6}+11)+(1-{0,(?{Level?|6}%10-2)/(?{Level?|6}%10-2)}kh1)-(1-{0,(?{Level?|6}%10-8)/(?{Level?|6}%10-8)}kh1)]]]]/[[[[round(0.8*?{Level?|6}+18)+(1-{0,(?{Level?|6}%10-3)/(?{Level?|6}%10-3)}kh1)-(1-{0,(?{Level?|6}%10-7)/(?{Level?|6}%10-7)}kh1)]]]] If you attempt using it while talktomyself is enabled, it resolves correctly and gives correct numbers for post-errata 4e skill DC's for any level entered. If you attempt using it while talktomyself is not enabled, it doesn't work because of division by 0 if the level entered ends with 2, 8, 3, or 7. This is very frustrating, as it necessitated rewriting the macro entirely in a much more complex way in order to avoid using division by zero for the conditional. Description of Your Setup (Browser + Version, Operating System, etc.) I doubt this is relevant, but I am using Google Chrome 54.0.2840.99 m on Windows 7. EDIT: fixed some mistakes in the description of the reproduction method.
Yeah, Dev Team's aware of this one . Maybe adding a really small number to the denominators might function as a workaround? DC's at level ?{Level?|6}: [[[[floor(0.5*?{Level?|6}+8)]]+[[ceil(?{Level?|6}/20)-1]]]]/[[[[round(0.7*?{Level?|6}+11)+(1-{0,(?{Level?|6}%10-2+1e-10)/(?{Level?|6}%10-2+1e-10)}kh1)-(1-{0,(?{Level?|6}%10-8+1e-10)/(?{Level?|6}%10-8+1e-10)}kh1)]]]]/[[[[round(0.8*?{Level?|6}+18)+(1-{0,(?{Level?|6}%10-3+1e-10)/(?{Level?|6}%10-3+1e-10)}kh1)-(1-{0,(?{Level?|6}%10-7+1e-10)/(?{Level?|6}%10-7+1e-10)}kh1)]]]]
1480264895

Edited 1480264960
You may have misunderstood my problem. Dividing by zero is the goal here, as it creates a clearly binary situation. I am using {0,(X-A)/(X-A)}kh1 as kind of a logic gate: if X isn't equal to A, it always outputs 1. If X equals A, it outputs 0 in talktomyself (which is perfect for my purposes, completing the logic gate), but breaks the macro outside of talktomyself. In other words, I'm using division by zero to implement an if/then/else clause as the macro system doesn't support it natively. And my woe is that my if/then/else implementation works only in talktomyself, but not outside of it.
To further clarify: using the code that you wrote gives incorrect results for skill DC's at levels which end in 2, 3, 7, or 8, which defeats the point. Using the code I wrote gives correct results for all levels 1-30, but only in talktomyself.
1480266968

Edited 1480268013
if X isn't equal to A, it always outputs 1. If X equals A, it outputs 0 This will do the same as long as A is a non-negative integer: [[ 1 - {-1, X}=A ]]
Wow, thanks! That makes this vastly simpler.
1480299339

Edited 1480457731
Indeed! In case you're interested, here's an extension of that method, which negates the need for round() functions: <a href="https://gist.github.com/Silvyre/168aaacae98039f9b0a102bbf5bd3355" rel="nofollow">https://gist.github.com/Silvyre/168aaacae98039f9b0a102bbf5bd3355</a>