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

Toggle option in ChatSetAttr?

Is there a way to toggle an attribute using ChatSetAttr? That is, turn it on if it's off, or turn it off if it's on, using one command?
1586540189
GiGs
Pro
Sheet Author
API Scripter
It depends what its value is. Most toggles use value 1 for on, and 0 for off. If that's the case you can set the value to [[1-@{attribute}]].
1586540545
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
If it's a matter of toggling between 0 and 1, you can use the math formula of x = 1 - x.
It's for Inspiration. (Yeah, I know, I already use Robin's Inspiration Tracker, but I really want to be able to use custom status markers for Inspiration, so I'm trying to do something on my own)
1586543711
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
If you are using status markers, try token-mod. It does have a toggle function.
Keith, I'm already using tokenmod for the marker. But to change the attribute on the character sheet I need ChatSetAttr (unless I am missing something, which is 110% likely!).
1586545357

Edited 1586545500
Dumbhuman
Pro
Marketplace Creator
It's a strange attribute, because the on state is "on" but the off state is "0".  You'd likely have to use evaluate, which means giving that access to players if you want them to be able to use it (though I suppose giving inspiration is really the DM's job anyway). The command below worked for me: !setattr {{ --sel --evaluate --inspiration#("%inspiration%"!="on")?"on":"0" }}
Thank you, KC! I will try that out and see if it works for me.
1586546888

Edited 1586548080
This will work for something that is purely visual, like inspiration, without issue. HOWEVER, I was messing with this last night to turn global attack modifiers on and off and ran into an issue. It works for them visually, I can see the check added/removed when I run the command, but when you trigger a roll it seems to partially honor the last status for the modifier that you manually set on the sheet. So, if you last turned it off manually it doesn't roll the modifier at all and if you last turned it on manually it will still roll the modifier but some parts of the roll template aren't filled out. My guess (I understand the API just enough to be dangerous) is that this has something to do with the sheetworkers issue.
1586549236
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Global Attack and Damage Modifiers cannot be reliably set with the API. This is due to how the sheet is set up.
KC, quick question: if I wanted to insert conditional text in the command you provided -- like one message for gaining inspiration, and one for using it -- where would I put it?
1586554563

Edited 1586554872
Dumbhuman
Pro
Marketplace Creator
Jay R. said: KC, quick question: if I wanted to insert conditional text in the command you provided -- like one message for gaining inspiration, and one for using it -- where would I put it? Something to show in general chat?  Something like this seems to work: !setattr {{ --charid @{target|character_id} --evaluate --inspiration#("%inspiration%"!="on")?"on":"0" --inspirational_text#("%inspiration%"!="on")?"You are feeling inspired to do something great soon!":"Your inspiration has given you an advantage!" }} @{target|inspirational_text} I tried it with @{selected} syntax first, but it didn't like that very much.  Of course, you'll want to create an inspirational_text attribute on all of your player characters beforehand or you'll get some error messages spit up for the first time you run it (after that it would be fine). Edit: Actually, if you want a message to show in chat, you're probably more interested in naming names than using a second person pronoun, so something along the lines of: !setattr {{ --charid @{target|character_id} --evaluate --inspiration#("%inspiration%"!="on")?"on":"0" --inspirational_text#("%inspiration%"!="on")?"@{target|token_name} is feeling inspired!":"@{target|token_name}'s inspiration has given an advantage!" }} @{target|inspirational_text}
Thank you so much!
keithcurtis said: Global Attack and Damage Modifiers cannot be reliably set with the API. This is due to how the sheet is set up. Thanks for the verification Keith. I have a sweet macro set up for my player's Barbarian. It triggers a 10 round rage condition via Combat Master, uses a charge of Rage (as ammunition) via 5eOGL Companion, sets a visible aura for his Storm Aura class ability via TokenMod, and was then supposed to turn on his global attack modifier for Rage via ChatSetAttr. Everything but that last bit works brilliantly. *shrug*
1586569504
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I present to you, the Keithcurtis Incredibly Lame Workaround for Global Damage Bonus not working with ChatSetAttr and Sheetworkers on Roll20 sheet .