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

API to add character Attributes

Is there an API script that can add an attribute to a character sheet. I am running a macro that randomised an NPCs HP and AC, (I have meta gaming players so randomise within reason) and was wondering if there was a way to add the attribute ac_formula  and fill its call box with 1d5+(NPC's AC Value - 3)
1617027302
The Aaron
Roll20 Production Team
API Scripter
I believe ChatSetAttr can add attributes that don't exist.  They would appear on the Attribute's page, but would only appear on the Character Sheet if there is a field for them already (which would generally mean the attribute would already exist...)
1617027727
timmaugh
Forum Champion
API Scripter
If ChatSetAttr can't automate it the way you want it to, InsertArg has the capacity to build an attribute's text (creating if it needs to), including some amount of sheet-item retrieval. You can see some of the recent back and forth between Erik and I in the script thread .
timmaugh said: If ChatSetAttr can't automate it the way you want it to, InsertArg has the capacity to build an attribute's text (creating if it needs to), including some amount of sheet-item retrieval. You can see some of the recent back and forth between Erik and I in the script thread . Just looking at that beast is making my mind melt. I would have no clue where to even begin to consider looking at for a potential place to start.
1617030097
David M.
Pro
API Scripter
Yep, the default behavior of ChatSetAttr is to create the attribute if it doesn't already exist. There is an option you can set to change this behavior (which you obviously don't want to use). From the documentation:  --nocreate  will change the script's default behaviour of creating a new attribute when it cannot find one; instead, the script will display an error message when it cannot find an existing attribute with the given name.
Ah excellent, I'll grab that wheb I am next on the laptop then and try and figure out the second part of it all.
Ok, ChatSetAttr worked for adding the extra attibute i needed, making things a lot faster for me, so thanks all for that. but currently my NPC's have a weird bug with their advantage query where it is just bringing up a partial string of code, i have gotten around this by changing the rtype to code from a macro that calls for an advantage query. I was hoping to change all NPC sheets in one go with ChatSetAttr with !setattr --allgm --rtype|{{query=1}} ?{Advantage?|Normal Roll,&#123&#123normal=1&#125&#125 &#123&#123r2=[[0d20|Advantage,&#123&#123advantage=1&#125&#125 &#123&#123r2=[[1d20|Disadvantage,&#123&#123disadvantage=1&#125&#125 &#123&#123r2=[[1d20} but all that does is call up an advantage query box and doesnt set the attribute. any ideas how to make the macro ignore the query advantage call and set the value i=on the character sheet?