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

[Question, sheetworkers] Can you create a temporary attribute?

1527900232

Edited 1527960555
Darren
Pro
Sheet Author
API Scripter
It occurred to me that I'm storing a lot of hidden fields whose values are regenerated every time the character loads.  So for instance, the character has a STR attribute.  Every time the character loads, I run a function that computes the character's weight capacity, damage bonus, etc.  Well, I don't need to store those value permanently since it is recomputed each time the character loads. My first thought was to save these values to global variables, but sheetworker docs state, "a variable declared inside the `<script type="text/worker">` but outside a function are currently per player , not per character." My next thought was to store them in input fields that are not named with the prefix "attr_" but I don't know how to, or if it is even possible to, get and set so-named input tags. Is there a solution, or should I just keep them as is?
1527911188

Edited 1527911224
GiGs
Pro
Sheet Author
API Scripter
You dont need to use sheet:opened on every sheet worker. Especially in your sheet, where you need to click an edit button to be able to edit stats, it would probably be better to skip the sheet:opened for a lot of stats, and only have them trigger when something actually changes. On one of my sheets, I have some stats responding to sheet:opened, things that might be easily altered, and others set only to run on change events.  That said, you can create attributes in a sheet worker, using setAttrs. If there isn't a corresponding input field to store the attribute, they wont be visible, but they will still exist and you can access them in other sheet workers.  Also, attributes (created with name="attr_something") are indeed great for storing global variables, and config elements that aren't meant to be exposed to the user (usually set with hidden).  This is the standard way of creating attributes on roll20 sheets, so I'm not sure what you mean when you say you aren't sure how to get and set them. You are doing it already in a bunch of your sheet workers. What am I missing?
1527912207
GiGs
Pro
Sheet Author
API Scripter
Oh! i should add: sheet workers can create attrributes, but they can't delete them. So any attribute you create isn't really temporary. Once you create it, you can change its value, but the attribute itself will always exist.
1527960528
Darren
Pro
Sheet Author
API Scripter
ugh... I had a typo in the second thought of my original message.  I meant to say, "store them in input fields that are NOT named with the prefix "attr_ ..."  I'm looking for a way to create temporary values that cease to exist once you log out."  Create them once when you load the character, then disappear when you log out.
1527960683
GiGs
Pro
Sheet Author
API Scripter
I see. No, that's not possible. You can store constants and global variables in the sheet worker section, but they are only accessible to scripts. The only way to store usable changeable data outside of sheet workers, is via the attribute (attr_) method.