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

if/elif ?

Hi everyone, I've been trying different things in macros functions but I did not succeed in using if nor elif functions. Does Roll20 even support it ? I've found quite agreat amount of possibilities in the wiki, but I'd like do create some conditionnal macros and as it is now, I can't find how. Briefly, here is my goal : I'm using a lot the "keep higher" and "keep lower" dices in my rules for damages Some Attributes are able to modify the number of dices in a way that a "keep higher" roll can be turned in a "keep lower" roll EXAMPLE : I'm wielding a long sword (2d6kh damages) My ennemy is wearing an armor wich diminish 2 dices of damages My sword will only have 2d6kh --> 1d6 --> 2d6kl damages This it how it works : it works great on table but I wish to find a solution to make it work on Roll20, and I think I'll need the if and elif functions to do it. Any idea ?
1432556170
The Aaron
Roll20 Production Team
API Scripter
(Moved to Specific Use, API is for posts about the JavaScript API.) Macros are not capable of if/else if behavior directly. Depending on how your query works, you can fake it with a sum of terms that are multiplied by an equation which results in 0 or 1 for a given circumstance.
I also have macros I'd like to be able to do that use different math depending on who's stat is higher, the acting character or the target. @Aaron, can you give an example of the faking you're talking about?
1432559837
The Aaron
Roll20 Production Team
API Scripter
Brian is really the master of this, I was hoping he'd come by and drop an amazing example... (Hint, hint Brian!!) I'll see if I can come up with something...
1432560560

Edited 1432560587
Finderski
Pro
Sheet Author
Compendium Curator
I don't think this is an amazing example but here's an example: [[{1d@{Unskilled}![Unskilled], 1d@{wilddie}![Wild Die]}kh1 -2[Unskilled Penalty] + {0,@{JackOfAllTrades}}kh1[Jack of All Trades Modifier]]] That formula takes the highest roll of either the Unskilled trait or a Wild Die (typically a d6) and then subtracts 2. Then it adds the higher of either 0 or the value of a Jack of All Trades (if it is checked). The trick is figuring out if something is true or false and then putting it in the curly brackets and resolve it with one value being something and the other being the other thing and figuring out which is the default. In the example above, 0 is the default, so that's why we do the keep higher. However, 0 could have been the default and if the other option was a -1, the we could have done a keep lower (kl). Does that make sense? I agree with The Aaron, Brian should come along with an amazing example. ;)
1432562815
The Aaron
Roll20 Production Team
API Scripter
So, here's an example of 1d6 if an attribute is 16: [[ 1d6 * [[ ({@{selected|ac},0}>16) * ({@{selected|ac},100}<16) ]] ]] Since > means "greater than or equal to", and in a { } group context, it will be the number of successes, the first term: ({@{selected|ac},0}>16) will be 1 if the @{selected|ac} is 16 or greater, 0 otherwise. Similarly, < means "less than or equal to", the second term: ({@{selected|ac},100}<16) Will be 1 if the @{selected|ac} is 16 or lower, 0 otherwise. Multiplying the two terms gives you 1 only in the case that both terms are 1, 0 otherwise, and then you multiply the whole thing by the dice expression you want in that case. Using the nested inline syntax makes the equation easier and the output cleaner. You can add a label for further clarity. Here's an example where I'm rolling 2d6 and adding an extra 1d6 if the AC of the target is 16: [[ 2d6 + ( 1d6 * [[ ({@{target|ac},0}>16) * ({@{target|ac},100}<16) ]] [AC:16?] ) ]] When AC is 16: When AC is not 16: It wrapped a little funny, but you can read the expression in the first one and see it has 1 [AC:16?] and the second has 0 [AC:16?] telling you what happened while hiding the seriously heinous looking syntax. Obviously, you're unlikely to have an ability that triggers when ac is exactly 16. If you need 16 or higher, you can leave off the second term, if you need 16 or lower, you can leave off the first term. When adjusting to another value, be sure the 100 in the second term is greater than whatever you are comparing against to make sure it still falls out. (You need the ,0 and ,100 to turn it into a number of successes check.) Hope that helps!
Iiiiinteresting. I'll have to think about this to see if I can make it work for my needs.
1432572016
The Aaron
Roll20 Production Team
API Scripter
So, in the game you're playing, armor decreases the number of dice a weapon attack does, but has a minimum of 1 die of damage? Something like this aught to work: [[ [[ {( 2 - (@{target|armor})),1}kh1 ]]d6 ]]
waw! Impressive! yes that's the main idea, except that if the Armor is stronger than the weapon, dices switch from kh to kl. Example: wielding a 3d6kh weapon against an armor with a protection value of 5, I'll lose 5d6 : 3d6kh becomes 4d6kl (3d6kh>2d6kh>1d6>2d6kl>3d6kl>4d6kl).
1432643036
The Aaron
Roll20 Production Team
API Scripter
Wow.. I'll have to think about that a bit... (Help Brian!!!!) Probably you'll have to make 2 terms, one for a stronger weapon, one for stronger armor, and choose between the two based on the difference.
Ah, clever! I have to admit that I'm also beginning to think about doing the maths myself when needed: it's too complicated for me! ^^ But your idea of making 2 terms seems cool as it is quite easy to see if the armor is stronger or else. It would just need a visible marker, unless it is possible for roll 20 to run a request such as "show @{selected! armor
1432650641

Edited 1432650761
Lithl
Pro
Sheet Author
API Scripter
I think that this does the trick, based on your description: [[[[{@{selected|weapon} - @{target|armor}, 1}kh1]]d6kh1 * [[{@{selected|weapon}*d1}>@{target|armor}]] + [[{@{target|armor} - @{selected|weapon}, 1}kh1 + 2]]d6kl1 * (1 - [[{@{selected|weapon}*d1}>@{target|armor}]])]] For weapon=3, armor=3, the result is 1d6kh1 * 1 + 3d6kl1 * (1 - 1) , which is 1d6. For weapon=3, armor=5, the result is 1d6kh1 * 0 + 4d6kl1 * (1 - 0) , which is 4d6kl1. For weapon=3, armor=1, the result is 2d6kh1 * 1 + 3d6kl1 * (1 - 1) , which is 2d6kh1. It does result in extra dice rolls (which will look odd if you use 3D dice), and it will result in misleading critical/fumble highlighting, but the number should be correct.
1432650787
The Aaron
Pro
API Scripter
Thanks Brian!!! =D
Waww cool, thanks a lot for this ! I'm gonna try ! It seems that if I like scripting, I don't realy like maths ^^
It does result in extra dice rolls (which will look odd if you use 3D dice), and it will result in misleading critical/fumble highlighting, but the number should be correct. You can add a cs0cf0 to those rolls to remove any critical highlighting, if you want.