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 .
×
This post has been closed. You can still view previous posts, but you can't post any new replies.

Defaulting to an attribute's "Max" value when the "Current" box is empty - has something changed?

I could've sworn that @{an attribute} (in a macro or ability) used to get you the "Max" value of the attribute if the "Current" box was left blank... but now it seems to just produce an empty string in that situation. Am I remembering wrong, or did that change sometime when I wasn't paying attention? Either way, does anyone know a trick to achieve that effect? I'd like to make my macros do the leg-work, rather than players having to fill in both boxes all the time for attributes that (in my case) are almost always at their maximum anyway.
1443740572
The Aaron
Roll20 Production Team
API Scripter
Hi Martin. &nbsp;I'm not precisely sure what you're asking, but I'll try to answer anyway. In a Character's Ability, @{ name } references the current value of the named attribute . In a Character's Ability, @{ name | max } references the max value of a named attribute . In a Macro, @{ character | name } references the current value of the named attribute on the specified character . In a Macro, @{ character | name | max } references the max value of the named attribute on the specified character . In a Macro or Character Ability, @{ selected | name } references the current value of the named attribute on the character of the selected token . In a Macro or Character Ability, @{ selected | name | max } references the max value of the named attribute on the character of the selected token . In a Macro or Character Ability, @{ target | message | name } or @{ target | name } references the current value of the named attribute on the character of the targeted token . &nbsp;The message part is optional and will be displayed in the prompt to target a token . In a Macro or Character Ability, @{ target | message | name | max } references the max value of the named attribute on the character of the targeted token . &nbsp;To get the max value for a target reference, the message part is required. See: <a href="https://wiki.roll20.net/Macros#Using_a_Selected_To" rel="nofollow">https://wiki.roll20.net/Macros#Using_a_Selected_To</a>...
Sorry, I didn't explain that very well - I'd been bashing my head against HTML etc all day, and my brain had gone all mushy. Let's try again: I was hoping to write Abilities that reference the Current value of the named Attribute if it's set, and the Max value if the Current value is not set. If I were using the API, that'd be something like (attribute.get("current") != "") ? attribute.get("current") : attribute.get("max") I thought @{attribute} used to do that for you in Abilities, but I guess I was mistaken. I was hoping someone had come up with a clever way of expressing the same formula in just an Ability, without having to resort to the API.
1443789402

Edited 1443789528
The Aaron
Roll20 Production Team
API Scripter
Ok, no problem. =D For a macro, all you have is math, so you have to create formulas that select the things you want. &nbsp;Someone like Brian or Diana will probably come by and write a better way of doing this, but here is what my mind goes to: First, write a term to determine if the current is empty: [[ {@{attr}+0,0}&gt;1 ]] This takes the count of items from the group ( denoted by { } ) which is greater than or equal to 1. &nbsp;I add +0 to the attribute in case it's the empty string. &nbsp;If it contains a word, it will crash the macro. &nbsp;The net result of this is 0 if the attribute is 0 or empty, and 1 otherwise. Next I combine that with multiplying by the attribute itself: [[ [[ {@{attr}+0,0}&gt;1 ]] * (@{attr}+0) ]] This term will have the current value of attr if it's &gt;0, and 0 otherwise. (Note the necessary +0 for an empty string.) Then I reverse the sense of that term for max: [[ (1-[[ {@{attr}+0,0}&gt;1 ]]) * @{char|attr|max} ]] I found that I had to put the character name in here, even though I'm doing it as a character ability. &nbsp;(That may be a bug, which I will look into separately.) &nbsp;By subtracting the result from 1, I get a 0 if there is a value for current and a 1 if there is not. &nbsp;I then multiple that result by the max value. Finally, I combine them both into a single expression: [[ [[ {@{attr}+0,0}&gt;1 ]] * (@{attr}+0) + (1-[[ {@{attr}+0,0}&gt;1 ]]) * @{char|attr|max} ]] Because of the multiplication, one term will always be 0, so I can add them both and get either the current value or max. That is probably not as simple as you'd like, but it does work so hopefully you'll find it useful.
1443789756
The Aaron
Roll20 Production Team
API Scripter
In the simpler case of knowing that one of the values is not filled in and wanting the other, you can use: [[ @{char|attr} + @{char|attr|max} ]] If either max or current is empty, it will have the value of the other. &nbsp;Note that this breaks if both are empty, and will give the sum if both have a value.
Ah, I see! That [[ {@{attr}+0,0}&gt;1 ]] thing is just the sort of trick I was looking for. ... and now I've had the chance to play around a bit with your suggestions, I think I've managed to slightly code-golf the&nbsp;(1-[[ {@{attr}+0,0}&gt;1 ]]) bit of the reverse one - I've come up with this, which seems to achieve the same thing with a little less clutter: [[ {@{attr}+0,1}&lt;0 ]] Anyway, that'll do the job nicely. Thanks! =)
1443891948
The Aaron
Roll20 Production Team
API Scripter
Great! &nbsp;Happy Rolling! =D