Using Macros to Map Discrete Points
Hey everyone, after some time of being frustrated with the lack of macro conditionals I have come up with a formula to transform a set of input numbers into a set of output numbers.
The Formula:
f(x) = y * floor(10000(-10000 * (x - t) ** 2))
This formula maps x to y when x = t
other wise f(x) = 0 when x != t
In Macro Form:
[[OUTPUT * (floor(10000 ** (-10000 * (INPUT - CHECK) ** 2)))]]
The Use (examples):
Say you like the number 7 very much and the number 9 a little.
So if a character makes a strength check you want to reward them for having those values accordingly
Macro:
[[2d6 + 1*(floor(10000**(-10000 * (@{strength} - 9) ** 2))) + 3*(floor(10000**(-10000 * (@{strength} - 7) ** 2)))]]
So now if their strength value is 9 they roll 2d6 + 1,
if their strength value is 7 they roll 2d6 + 3
otherwise they roll a plain old 2d6
As you can see this function gives us the ability to selectively apply modifications by repeatedly adding.
Another example would be to give an additional die roll to a token with their bar1 value = 1
ie: characters on deaths door are given an extra die roll to their action.
Macro:
[[2d6 + 1d6 * (floor(10000 ** (-10000 * (@{selected|bar1} - 1) ** 2)))]]
So if a character has bar1 = 1 they roll 3d6
otherwise they roll 2d6
For all but 1 number:
Say you hate the number 7 so a character with 7 strength rolls 1 less d6
Apply this:
[[OUTPUT * (1 - (floor(10000 ** (-10000 * (INPUT - CHECK) ** 2))))]]
Ex:
[[1d6 + 1d6 * (1 - (floor(10000 ** (-10000 * (@{strength} - 7) ** 2))))]]
So characters with strength = 7 will roll 1d6
but characters with any other value will roll 2d6
The simplified explanation as to why this works (and how to prevent it breaking):
f(x) = y * floor(10000(-10000 * (x - t) ** 2))
is just a very skinny bell curve which peaks at y when x = t
ideally in place of those two 10000 values you would use infinity but to avoid breaking anything in the macros ability to calculate I've found that using 10000 works pretty well.
If you have many discrete values very very near one another they may overlap a little and throw off your results so just increase the 10000 values to a larger number.
Here is an the first example in demos for you to play around with if you want to learn more:
https://www.desmos.com/calculator/0ac0jkelxp
With all that being said let me know if you find any errors in my math and thank you for reading.