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

Simplifying with Variables?

I apologize if I come across as a newb here, but there is a reason for that...  :P I am making some Macros, but they are extensively long and arduous in form, primarily because there seems to be a lack of variables?  I'm hoping someone can tutor me just slightly on how to more efficiently write out some of these Macros.  The primary culprit is the Automatic Bonus Progression rule that we use, which adds +1 Enhancement to weapons at levels 4, 9, 14, 15 and 17...  That's not so hard to write, but I have to copy/paste it repeatedly, everywhere. For example, my Great Cleave Macro (using [[ { 1, [[ {0,floor(level/4)}kh1 ]] }kl1 ]] as a base for Max(level/4,1) code, which already seems over-whelming): /me swings widely, hoping to take out as many foes as possible with a single powerful swing.  Target 1 -> Hit: [[1d20 + @{Thesslar|level} + @{Thesslar|strength_mod} + [[ {1,[[{floor(@{Thesslar|level}/4),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/9),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/14),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/15),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/17),0}kh1]]}kl1 ]]  - 3]]  Damage: [[ 4d6 + floor(@{Thesslar|strength_mod} * 1.5) + ((1+floor(@{Thesslar|level} /4))*3)*1.5 +  [[ {1,[[{floor(@{Thesslar|level}/4),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/9),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/14),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/15),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/17),0}kh1]]}kl1 ]] ]] Target 2 -> Hit: [[1d20 + @{Thesslar|level} + @{Thesslar|strength_mod} + [[ {1,[[{floor(@{Thesslar|level}/4),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/9),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/14),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/15),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/17),0}kh1]]}kl1 ]]  - 3]]  Damage: [[ 4d6 + floor(@{Thesslar|strength_mod} * 1.5) + ((1+floor(@{Thesslar|level} /4))*3)*1.5 +  [[ {1,[[{floor(@{Thesslar|level}/4),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/9),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/14),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/15),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/17),0}kh1]]}kl1 ]] ]] Target 3 -> Hit: [[1d20 + @{Thesslar|level} + @{Thesslar|strength_mod} + [[ {1,[[{floor(@{Thesslar|level}/4),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/9),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/14),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/15),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/17),0}kh1]]}kl1 ]]  - 3]]  Damage: [[ 4d6 + floor(@{Thesslar|strength_mod} * 1.5) + ((1+floor(@{Thesslar|level} /4))*3)*1.5 +  [[ {1,[[{floor(@{Thesslar|level}/4),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/9),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/14),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/15),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/17),0}kh1]]}kl1 ]] ]] Target 4 -> Hit: [[1d20 + @{Thesslar|level} + @{Thesslar|strength_mod} + [[ {1,[[{floor(@{Thesslar|level}/4),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/9),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/14),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/15),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/17),0}kh1]]}kl1 ]]  - 3]]  Damage: [[ 4d6 + floor(@{Thesslar|strength_mod} * 1.5) + ((1+floor(@{Thesslar|level} /4))*3)*1.5 +  [[ {1,[[{floor(@{Thesslar|level}/4),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/9),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/14),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/15),0}kh1]]}kl1 ]]  + [[ {1,[[{floor(@{Thesslar|level}/17),0}kh1]]}kl1 ]] ]] /w Thesslar This is a Standard Action and you are at -2 AC until your next turn. What I'd hope for is a way to put the Enhancement calculation into a variable so I could do: Target 4 -> Hit: [[1d20 + @{Thesslar|level} + @{Thesslar|strength_mod} + @{Thesslar|enh_bonus}  - 3]]  Damage: [[ 4d6 + floor(@{Thesslar|strength_mod} * 1.5) + ((1+floor(@{Thesslar|level} /4))*3)*1.5 +  @{Thesslar|enh_bonus} ]] I realize I could just manually change a variable to use, everytime I reach an appropriate level, but manually editing variables seems wrong (and requires me to remember to make that change... at the right time).  Is there a way to set a variable and do this in a cleaner fashion as indicated? Much thanks for any time spent answering this query,  Z
1618488841
The Aaron
Roll20 Production Team
API Scripter
There isn't a way to set attributes or create and set variables within macros. To do something of the sort would require the API (Pro subscriber perk). 
Disappointing, but understandable.   Much thanks for replying.  :)
1618491422
The Aaron
Roll20 Production Team
API Scripter
You might find some good workaround tips here:&nbsp;<a href="https://app.roll20.net/forum/post/5899495/stupid-roll20-tricks-and-some-clever-ones/?pageforid=5899495#post-5899495" rel="nofollow">https://app.roll20.net/forum/post/5899495/stupid-roll20-tricks-and-some-clever-ones/?pageforid=5899495#post-5899495</a>
1618491982

Edited 1618492048
Ziechael
Forum Champion
Sheet Author
API Scripter
You could create a custom attribute called something like 'autobonus' and input the following as the value: [[ {1,[[{floor(@{level}/4),0}kh1]]}kl1 ]]&nbsp; + [[ {1,[[{floor(@{level}/9),0}kh1]]}kl1 ]]&nbsp; + [[ {1,[[{floor(@{level}/14),0}kh1]]}kl1 ]]&nbsp; + [[ {1,[[{floor(@{level}/15),0}kh1]]}kl1 ]]&nbsp; + [[ {1,[[{floor(@{level}/17),0}kh1]]}kl1 ]] Then you'd be able to replace all of that in your macro with a single @{autobonus} call? note: It's likely that the custom attribute won't play nice with queries due to the problematic characters it contains but that's a problem for another day
Ziechael said: You could create a custom attribute called something like 'autobonus' and input the following as the value: [[ {1,[[{floor(@{level}/4),0}kh1]]}kl1 ]]&nbsp; + [[ {1,[[{floor(@{level}/9),0}kh1]]}kl1 ]]&nbsp; + [[ {1,[[{floor(@{level}/14),0}kh1]]}kl1 ]]&nbsp; + [[ {1,[[{floor(@{level}/15),0}kh1]]}kl1 ]]&nbsp; + [[ {1,[[{floor(@{level}/17),0}kh1]]}kl1 ]] Then you'd be able to replace all of that in your macro with a single @{autobonus} call? I tried this... it just returns 0.&nbsp; :(
Zylphyr said: Ziechael said: You could create a custom attribute called something like 'autobonus' and input the following as the value: [[ {1,[[{floor(@{level}/4),0}kh1]]}kl1 ]]&nbsp; + [[ {1,[[{floor(@{level}/9),0}kh1]]}kl1 ]]&nbsp; + [[ {1,[[{floor(@{level}/14),0}kh1]]}kl1 ]]&nbsp; + [[ {1,[[{floor(@{level}/15),0}kh1]]}kl1 ]]&nbsp; + [[ {1,[[{floor(@{level}/17),0}kh1]]}kl1 ]] Then you'd be able to replace all of that in your macro with a single @{autobonus} call? I tried this... it just returns 0.&nbsp; :( Never mind, I see that I made a mistake in applying the Attribute, indeed this works nicely!