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

Conditional Statements in Macros

December 22 (9 years ago)
I had done some digging around, looking for a way to do some kind of IF statement. I want to do the following:
if(1d20)>@{target|AC} then **Damage**: [[3d6]]

I came across this, in a article claiming it was a workaround for an if-statement in a roll20 macro.

[[ 1d12 + 5[STR] + ( ?{Two-Handed Weapon?|0}[TwoHanded?] * floor( 5[STR] * .5) ) ]]

Can someone explain that bit of macro for me? I am an experienced coder, but don't have mentor-status, thus I am limited to macros, rather than using an API.
December 22 (9 years ago)

Edited December 22 (9 years ago)
[[ 1d12 + 5[STR] + ( ?{Two-Handed Weapon?|0}[TwoHanded?] * floor( 5[STR] * .5) ) ]]
The intention, here, is that the user of this macro would input 1 into the Roll Query when the user wishes the macro to add 1.5 times their strength modifier to a roll. That is to say, ?{Two-Handed Weapon?} == 1 implies that
[[ 1d12 + 5[STR] + ( ?{Two-Handed Weapon?|0}[TwoHanded?] * floor( 5[STR] * .5) ) ]]
= [[ 1d12 + 5[STR] + ( 1 * floor( 5[STR] * .5) ) ]]
= [[ 1d12 + 5 [STR] + floor(2.5) ]] i.e. [[ 1d12 + floor(7.5) [STR * 1.5] ]]

It's not possible to truely hide macro elements using conditional logic without the usage of the API, which is only available within games created by Pro users.

That said, while "if(1d20)>@{target|AC} then **Damage**: [[3d6]]" may not be achievable, you may be satisfied with "if(1d20)>@{target|AC} then **Damage**: [[3d6]] else **Damage**: [[0]]" using a binary technique similar to above (in conjunction with Target Number / Successes). e.g.
**Damage**: [[ {1d20 + ?{Modifiers|0}}>@{target|AC} * [[3d6]] ]]