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 .
×

Assistance with conditional statements

Hey, I have been playing around with roll20 for a while now with some friends, and wanted to try making my own game. I am having some issues trying to figure out how to calculate a value based on another value (so if number A is 1-4, number B should be 2. 5-9 = 3, 10-13 = 4, etc etc.) I've read the FAQ and Wiki related to conditional statements, but it is confusing me (never been 100% good with math, especially when letters become involved), and would like a little bit of help, if possible. Thanks in advance, really enjoy playing with others here.
1476491213
Tetsuo
Forum Champion
I've never personally understood the default conditional statement math, but the PowerCards API script can replicate if then statements fairly easily
1476493174

Edited 1476503546
PowerCards does make this quite easy. However, if you're only dealing with uniformly-increasing values, the step functions f(x, y) = ceil(x / y) or f(x, y) = floor(x / y) can often be of use. To give some examples: 1. [[ 1 + ceil((1d20 + ?{Mods}) / 4) ]] resolves to equal: 2 if and only if 1 ≤ 1d20 + ?{Mods} ≤ 4, or 3 if and only if 5 ≤ 1d20 + ?{Mods} ≤ 8, or  4 if and only if 9 ≤ 1d20 + ?{Mods} ≤ 12, or 5 if and only if 13 ≤ 1d20 + ?{Mods} ≤ 16, or 6 if and only if 17 ≤ 1d20 + ?{Mods} ≤ 20 2. [[ 2 + floor((1d20 + ?{Mods}) / 5) ]] resolves to equal: 2 if and only if 1 ≤ 1d20 + ?{Mods} ≤ 4, or 3 if and only if 5 ≤ 1d20 + ?{Mods} ≤ 9, or 4 if and only if 10 ≤ 1d20 + ?{Mods} ≤ 14, or 5 if and only if 15 ≤ 1d20 + ?{Mods} ≤ 19, or 6 if and only if 20 = 1d20 + ?{Mods} If you're not dealing with dice at all, the necessity for uniformly-increasing values disappears and you can make use simpler functions like this: Number B: [[ 2 + {?{Number A|1} + d0}>5 + {?{Number A} + d0}>10 [+etc.] ]] Which is the function described in this thread's original post.
would this work in the html side of creating a custom character sheet? Basically, as a character levels, I want the character sheet to automatically increment certain stats (such a prof bonus) based on the character's current level. This is nothing that would be used in a dice roll, or displayed in chat. It is all kept to the confines of that character's specific character sheet. For example, if my character is level 5, I want the prof bonus to go from +2 to +3.  I have other areas I will be needing something similar for, so once I figure out this aspect, the rest should fall into place. Please note I am creating a custom character sheet, not using a template.
1476503155
Tetsuo
Forum Champion
FOr that, I would look into how the dnd 5e sheet handles its profficiency bonus, as it follows a similar structure.
1476503300

Edited 1476503369
floor() and ceil() can be used within autocalculated Attributes; yes. However, I'd also recommend looking into Sheet Worker Scripts as an alternative method of handling such functionality.
So if I am reading the page correctly related to sheet workers, I can create a function that utilizes an if statement to compare values, and output a final value, correct? I.e. I open my character sheet, with me character level being 5, the script runs, and if the character level meets or exceeds a predefined value (5 in this case), the prof-bonus will be set to the value set aside for that level range. example (psuedo code, just to simplify) if(Level >= 5) { profBonus = 3; } else { profBonus = 2; } or would it be better to use a state switch in the function for each level available game (say 1-20), and set any level specific values per switch?