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

[Custom Sheet] Setting Default Values in "Attributes & Abilities" Tab

1527646144

Edited 1527646388
I use a lot of APIs that refer to several attributes of a character sheet that I've created, but I have a problem that unless some of the values of the character are changed manually, they aren't recognized in the list of attributes according to the APIs. The basic fix I attempted with this was make a default setter for the page, but even then, the values change but aren't added to the attribute list. Like so... on("change:default_info", function() { setAttrs({"color": "gray"}); setAttrs({"nickname": "Character"}); setAttrs({"class": "soldier"}); ... ... setAttrs({"tool2_prof-level": 0}); setAttrs({"tool3_prof-level": 0}); }); The values are all changed but they don't come up in the attribute list. In the documentation for building character sheets it says... You can also optionally include a value attribute on the tag, which will define the default value for the field. For example, <input type="number" name="attr_AC" value="0" /> would define an "AC" field with a default value of "0". If no default value is specified, it is an empty string (""). This however doesn't add the values to the attribute list to be detected by APIs. Is there anyway I can write javascript to force it into that attribute list, or some other method I'm unaware of. Thanks. EDIT: I also know that autocalc-ing values can add them to the attribute list, but I'm not quite sure how I can implement that in a way that can be one time use.
1527649878
GiGs
Pro
Sheet Author
API Scripter
Attributes don't need to be in that Attribute list to be used in macros, scripts, and what not. Roll20 will use the default values even though they aren't displayed in that list. What situations have you tried using attributes with default values, where they aren't working?
G G said: Attributes don't need to be in that Attribute list to be used in macros, scripts, and what not. Roll20 will use the default values even though they aren't displayed in that list. What situations have you tried using attributes with default values, where they aren't working? I have a script that sets the attribute to a value !setatt @{selected|token_id} cover 4 Which is suppose to change the attribute "cover" to 4, to indicate +4 to their defense. However, unless it's in the attribute list it won't change value when hitting the macro.
1527653588
GiGs
Pro
Sheet Author
API Scripter
Ah, an API script issue. i see.  If that's a home-grown script, you should include a check to see if the attribute exists, and if not, create it within the script. You could also use ChatSetAttr, which is great for setting the values of attributes, and will work if the attribute doesn't exist.
1527659056

Edited 1527664413
Jakob
Sheet Author
API Scripter
Agreeing with GG here. 1) Update your API script to create attributes when none exist; or 2) Use another script, like ChatSetAttr, which does that; or 3) I'm pretty sure that setting values with setAttrs() will  add them to the attributes & abilities list, even if you set them to their default value. You have to close & re-open the sheet to actually seem them on the attributes & abilities page, however. By the way, it's more performant to write setAttrs({ "color": "gray", "nickname": "Character", "class": "soldier", ... "tool2_prof-level": 0, "tool3_prof-level": 0, }); instead.
Thanks for the API suggestion and the alternative syntax. ChatSetAttr does add it to the attribute list.