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

Help with Math

I need some assistance with a formula for a macro in my game, because I am not very mathematically inclined. I need a formula that when it pulls the value of attribute @{X}, X having a value of either 0 or a positive integer, that it produces 0 if X was 0, or 1 otherwise. Since this is for a macro, it has to be something which fits inside an inline roll. Anyone with math skills able to help me on this?
1428247802
The Aaron
Pro
API Scripter
Any idea what the possible range of the attribute is? This should be 0 or 1: [[ (((@{X}/1000)+.49999)d1) ]] Hopefully Brian will be by soon, he's brilliant at these things...
1428255272

Edited 1428255492
Here's a little modulo trick that works for positive integers of any size: [[ ((@{X}+2) % (@{X}+1)) ]] (Edit: formatting.)
1428255466

Edited 1428255746
Kryx
Pro
Sheet Author
API Scripter
Simon S. said: Here's a little modulo trick that works for positive integers of any size: [[ ((@{X}+2) % (@{X}+1)) ]] How about the reverse? (Return 0 if it's above 0, return 1 if it's 0)
1428256242
The Aaron
Pro
API Scripter
Mark said: Simon S. said: Here's a little modulo trick that works for positive integers of any size: [[ ((@{X}+2) % (@{X}+1)) ]] How about the reverse? (Return 0 if it's above 0, return 1 if it's 0) That is clever! I didn't realize we had access to modulo? Could reverse with: [[ ((((@{X}+2) % (@{X}+1))-1)*-1) ]]
1428258042
Lithl
Pro
Sheet Author
API Scripter
Travis M. said: I need some assistance with a formula for a macro in my game, because I am not very mathematically inclined. I need a formula that when it pulls the value of attribute @{X}, X having a value of either 0 or a positive integer, that it produces 0 if X was 0, or 1 otherwise. Since this is for a macro, it has to be something which fits inside an inline roll. Anyone with math skills able to help me on this? [[((@{X} + 1) - abs(@{X} - 1)) / 2]] That will produce min(@{X}, 1) . With the guarantee that X is a non-negative integer, the result will either be 0 or 1. Mark said: Simon S. said: Here's a little modulo trick that works for positive integers of any size: [[ ((@{X}+2) % (@{X}+1)) ]] How about the reverse? (Return 0 if it's above 0, return 1 if it's 0) If you have a formula that produces 0 in one case and 1 in all other cases, you can flip that result by subtracting your formula from 1. 1 - 0 produces 1, and 1 - 1 produces 0.
1428258856

Edited 1428258920
Kryx
Pro
Sheet Author
API Scripter
Brian said: Mark said: Simon S. said: Here's a little modulo trick that works for positive integers of any size: [[ ((@{X}+2) % (@{X}+1)) ]] How about the reverse? (Return 0 if it's above 0, return 1 if it's 0) If you have a formula that produces 0 in one case and 1 in all other cases, you can flip that result by subtracting your formula from 1. 1 - 0 produces 1, and 1 - 1 produces 0. The above part is key. I have 0, 2, 6, 3.5, etc. I'm just optimizing a formula at this point though. Aaron's reverse is decent, but it doesn't shorten my original formula. I was hoping to find a short version like Simon posted.
1428259491
The Aaron
Pro
API Scripter
Yeah, like I said, Brian is brilliant at this stuff. =D
Thanks for the help guys! Actually, after posting this I walked away from my computer and bumped into a friend, who I asked about this problem. He managed to make a shorter one, although it's not as useful in as many situations as your guys' work: @{y}=ceil(@{x}/(@{x}+1)) Works fine in math-only rolls, and when doing things like [[1d20+@{y}]] (which is what I was using it for), but it doesn't seem to work for things like [[(@{y})d6]]. I'll keep the ones you guys gave me saved for when I inevitably need to do a roll like that, though. Will come in handy when/if I get around to making a sheet that's also a fully automated character builder...
1428288862

Edited 1428288915
Gauss
Forum Champion
Travis , you cannot use "ceil" for the "x" portion of xDy unless you put it in an inline roll. Most people get around this by using +0.5. The dice roller automatically rounds (0.5 up, 0.4999 down) the "x" portion of xDy. Example: (3/2+0.5)d6 = 2d6
1428294183
Lithl
Pro
Sheet Author
API Scripter
Mark said: Brian said: Mark said: Simon S. said: Here's a little modulo trick that works for positive integers of any size: [[ ((@{X}+2) % (@{X}+1)) ]] How about the reverse? (Return 0 if it's above 0, return 1 if it's 0) If you have a formula that produces 0 in one case and 1 in all other cases, you can flip that result by subtracting your formula from 1. 1 - 0 produces 1, and 1 - 1 produces 0. The above part is key. I have 0, 2, 6, 3.5, etc. I'm just optimizing a formula at this point though. Aaron's reverse is decent, but it doesn't shorten my original formula. I was hoping to find a short version like Simon posted. I count three solutions in this thread which will result in 0 for X=0 and 1 for X>0. In all of those cases, (1 - @{solution}) will produce 1 for X=0 and 0 for X>0. Travis M. said: Works fine in math-only rolls, and when doing things like [[1d20+@{y}]] (which is what I was using it for), but it doesn't seem to work for things like [[(@{y})d6]]. I'll keep the ones you guys gave me saved for when I inevitably need to do a roll like that, though. Will come in handy when/if I get around to making a sheet that's also a fully automated character builder... You cannot use any functions for calculating the number of dice, unfortunately. Simon's solution ought to work, though.