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 .
×
Advertisement Create a free account

Version Updates and Deleting Attributes?

Is there a common pattern or means of performing updates when opening a new version of a sheet for the first time? For example, to populate fields normally modified by sheet worker events or to replace existing attributes? My approach is using a hidden "attr_version" and moving through migration steps to update it to current: // Version update for new or modified attributes on("sheet:opened", function() { getAttrs(["version", "sheettype"], function(v) { const version = parseInt(v.version) || 0; var attrs = {}; // get attribute updates for each version until the sheet has completed all steps // NOTE: to maintain backwards compatibility with sheets predating the version attribute, all steps will be performed for new sheets if (version < 1) { if (v.sheettype !== "mortal1") { attrs["game_line"] = getGameLine(v.sheettype); attrs["edition"] = getEdition(v.sheettype); } attrs["version"] = 1; } /* * if (version < 2) { * attrs["version"] = 2; * } */ if (Object.keys(attrs).length) { setAttrs(attrs); } }); }); (Note that for the sake of backwards compatibility, new sheets will also run through all the migration steps.) As a related question, is there a way to delete a sheet attribute? I can always set it to an empty string or some default value, but it'd be nice to be able to remove it from the "attributes" list altogether as a means of avoiding clutter. Use cases include having a   "clear section" button, resetting selected toggles, or migrating sheet values from a hard-coded list of "attr_item1", "attr_item2", etc to a repeating section. (If there is not currently a way to do this in sheet workers, can one be considered? It feels bad to leave a bunch of obsolete attributes.)
1585747600

Edited 1585747636
GiGs
Pro
Sheet Author
API Scripter
There's no way to delete attributes with sheet workers. You can do it with the API, though. Having the ability to do it in sheet workers would be nice for version upgrade housecleaning. And your method of versioning is basically a variant of the most common way to do this. 
Thanks for pointing me to the API scripts! I haven't really looked at those. Would it be reasonable to set a "sys_remove_attrs" attribute with a space-separated list in a sheet worker and have a Campaign "ready" event handler that checks for that attribute and removes the specified attributes and the "sys_remove_attrs" attribute? It may not be an immediate cleanup, but could work as an automated "eventual" cleanup. (I'm not sure if there's a set of API scripts included in all games that I can contribute to with an event handler.)
1585751908
GiGs
Pro
Sheet Author
API Scripter
API scripts can only be used by Pro user-created campaigns, so they aren't usually linked to character sheets. Some sheets have a Companion Script, to provide extra features for those who are Pro. You could have an event-based attribute cleanup in such a script, but I cant see any reason you would. Attributes exist for a purpose, and they shouldnt be being created and then removed over and over. If you do a version upgrade and feel the need to get rid of now-redundant attributes, it would be better to provide a function through the API to let people do this on-demand - not as an event that runs constantly. For example, what happens when someone create an attribute with the same name as one your event is looking for to delete?