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

Macro with if statement and absolute value

Hi fellow Roll20ers, I am struggling with an Ability Macro where I would need to : make the sum of 2 Attributes, let's call it S consider if S is positive or negative if positive I need to roll : ( 2 + S )d6k2 if negative I need to roll : ( 2 + abs(S) )d6kl2 Could someone please help me with my ambitious Macro ?
1585875240
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Unless you can work that into a single mathematical expression, you are probably out of luck. Macros are not really a programming language. They lack language features such as conditional logic or looping.
I cannot think of a way to work that into a mathematical expression sadly. I guess it was too ambitious. Thanks anyway for taking the time to answer me keithcurtis.
1585905750
GiGs
Pro
Sheet Author
API Scripter
You could report both positive and negative, and choose the result. Something like &{template:default} {{name=Dice roll}} {{result=[[@{attribute1}+@{attribute2}]]}} {{Positive=[[abs(@{attribute1}+@{attribute2})+2]]d6kh2}} {{Negative=[[abs(@{attribute1}+@{attribute2})+2]]d6kl2}} (all on one line) Then choose the correct roll based on the result.
I will end up doing something like this, thanks for the advice GiGs. For what it worths, I added some square brackets in your code to have the dice rolls work : &{template:default} {{name=Dice roll}} {{result=[[@{attribute1}+@{attribute2}]]}} {{Positive=[[[[abs(@{attribute1}+@{attribute2})+2]]d6kh2]]}} {{Negative=[[[[abs(@{attribute1}+@{attribute2})+2]]d6kl2]]}}
1585970574
GiGs
Pro
Sheet Author
API Scripter
Ah yes, good point :)