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

Additional math functions for character sheets and macros.

Score + 12
July 11 (10 years ago)

Edited July 11 (10 years ago)
Diana P
Pro
Sheet Author
I know that https://app.roll20.net/forum/post/1242264/min-x-y-... is asking for the min and max function, but we need more than just those. And not everything can be done with workarounds like the min and max functions can.

I am posting this on behalf of Windsor M. (who can't) since he was trying to help me with max-load calculations for encumbrance on the D&D3.5 sheet. The big math function we need is a power function (a^b) and since the b is a derived variable based on the starting strength skill, we could not come up with a workaround.

So:

There are some things we simply cannot calculate with linear functions. For example, this:
is not a linear function. It replicates (exactly) a table of values, and while the formula behind it has been broken down into round(n), ceil(n), floor(n) and abs(n) ... it still requires one (unavoidable) use of the pow(a, b) function with a static base and a variable exponent.
My suggestion is that we expand the available math functions. A few key ones are: log, exponential, max, min, sin, cos. With those building block functions most others can be derived. With that being said, it might not be a bad idea to include native functions for some of the common derivable functions.

Below is a list of functions showing their JavaScript calls followed by some possible syntax in roll20.
Power, Exponential, & Log Functions:
Math.log(n) =        ln(n)
Math.exp(n) = e^n = exp(n)

Math.pow(a,b) = Math.exp(Math.log(a)*b) =    a^b    = pow(a, b)
                Math.log(n)/Math.log(b) = log[b](n) = log(b, n)
                Math.pow(n, 1/r)        =  n^(1/r)  = nroot(r, n)
Math.sqrt(n)  = Math.pow(n, 1/2)        =  n^(1/2)  = sqrt(n)

As you can see above, even many of the other functions in Math can be derived from these 2 building block functions.


Pick functions:
Math.max(a, b, ...) = max(a, b)
Math.min(a, b, ...) = min(a, b)

Even if it only picks between two numbers it is an extraordinarily useful tool to have. This portion of the suggestion mirrors: https://app.roll20.net/forum/post/1242264/min-x-y-and-max-x-y-functions#post-1845953


Trig functions:

Math.sin(t), Math.cos(t)
These are the most important trig functions, practically everything else can be built from them. I don't think we'd need their inverses, but the Math object in JavaScript does have those (perhaps Math.atan2(a, b) would be handy, since we don't have conditionals)

With more math tools available, not only would character-sheet builders benefit, but macros would get a boon as well!
July 12 (10 years ago)
Roger A.
Sheet Author
not sure if you have seen this post https://app.roll20.net/forum/post/882997/css-wizardry#post-944536 it explains how to work around these things, but I agree that native support for the functions would be MUCH better.
July 12 (10 years ago)
Diana P
Pro
Sheet Author
I am aware of that post (and refer to it often) and it explains most of them. The one I was running into issues with was the power. It does and I can calculate power if I know what power I am using but when it's a calculated value (2^(ceil((strength)/5) -3) in my use case; strength can be between 1 and ??-higher than 29 at anyrate), we couldn't figure out how to would calculate that one without some kind of recursion. And I'm not willing to bake the API into a community sheet.
See also this thread: https://app.roll20.net/forum/post/1260406/rewrite-...
One could argue that one thread is a subset of the other. What I really think needs to happen is someone needs to write a formal specification of what a new Roll20 dice roller should look like, so that everyone can band together under one well-specified suggestion.
October 21 (9 years ago)
Loki
Sheet Author

Roger A. said:

not sure if you have seen this post https://app.roll20.net/forum/post/882997/css-wizardry#post-944536 it explains how to work around these things, but I agree that native support for the functions would be MUCH better.
That workaround dosn't work for the log(n) and even if one changes to a working method as they are still only an approximation that isn't accurate for large numbers. So calculating sometihng like 2^x=n -> x=logBase2(n)=ln(n)/ln(2) is impossible.

That's something I would need to calculate how many life bars a charackter has to determine the HP_MAX of a character (HP_MAX=(Constitution+Diziplin+Presence)*(ciel(logBase2(Body+1)+1)). On the physical sheet there is a penalty next to each bar, so players just need to compare that with thier body modifier and cross out any bars with a higher penalty as well as any HP boxes exeeding their Constitution+Diziplin+Presence value (penalty=abs(floor(pow(2,floor((HP_MAX-HP_CUR-1)/(Constitution+Diziplin+Presence)))-1))). Right now I depend on a user input for the number of bars, this way I still can make use of the lifebar functions in Roll20's token system, but I'd if the user needs to input as few things as possible to keep it user friendly.