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

Default Value for 'attributes' of a Token

I want create a Macro accessing the values of the token bar (The Tokens are not necessary lnked to a Character). @{selected|bar1} works fine, as long a as i initial put some value in, but not if i left the token bar attributes in their initial state after dragging the token onot the map. How do i program the macro to use some default value, if no value for a token bar 'attribute' is set? Complete Macro: @{selected|gm_roll_opt} &{template:DSA-Kampf-Treffer} {{name=Nahkampf}} {{target=[[0]]}} {{TPArt=[[0]]}} {{zone=[[1d20]]}} {{damage=[[[[(@{selected|bar1})]]d6 + @{selected|bar1|max}]]}}
<a href="https://app.roll20.net/forum/post/5899495/roll20-tips-and-tricks-innovative-solutions-to-common-problems/?pageforid=9102789#post-9102789" rel="nofollow">https://app.roll20.net/forum/post/5899495/roll20-tips-and-tricks-innovative-solutions-to-common-problems/?pageforid=9102789#post-9102789</a> You should be able to simply add a '0' in front of each attribute to avoid an error message for an invalid/empty attribute. @{selected|gm_roll_opt} &amp;{template:DSA-Kampf-Treffer} {{name=Nahkampf}} {{target=[[0]]}} {{TPArt=[[0]]}} {{zone=[[1d20]]}} {{damage=[[[[(0@{selected|bar1})]]d6 + 0@{selected|bar1|max}]]}} If you want the default to be some other non-zero number, then that will be different.
Since the linked workaround is a String concatenation, this does not work for other numbers than zero. It’s a partly solution for me.
Tobias said: Since the linked workaround is a String concatenation, this does not work for other numbers than zero. It’s a partly solution for me. What value do you want the default to be? Will it always be the same, or will it be character dependent?
the default value should be 1.
For a non-zero default value you have to specify things a little differently, such as [[1+(@{attr})-1]] The key being the default value is added one side of the attribute then removed the other side. When the attribute has a value the whole roll is calculated so the positive and negative versions of the default value cancel out. When the attribute is missing or empty the middle part prevents the cancelling out giving you your default value. So your macro updates to @{selected|gm_roll_opt} &amp;{template:DSA-Kampf-Treffer} {{name=Nahkampf}} {{target=[[0]]}} {{TPArt=[[0]]}} {{zone=[[1d20]]}} {{damage=[[ [[1+(@{selected|bar1})-1]]d6 + [[1+(@{selected|bar1|max})-1]] ]]}}
This works. Thank you very much