I notice in the comments of your script, you say "roll20 apparently can't get values based on ids?" Sheet Worker Scripts (the things that are part of character sheets, as opposed to API scripts) are sandboxed, so that they can't manipulate the DOM; if sheet workers had access to the document object, you could use a sheet worker to do literally anything you wanted to any part of the VTT, not just manipulate a character sheet. Sheet workers operate on an event system: opening the sheet for the first time in a session, changing an attribute, adding a repeating item, or deleting a repeating item are all events they can respond to. (I think they can respond to reordering repeating items as well, but I'm not 100% certain about that.) For example: on('change:myHealth0 change:myHealth1 change:myHealth2 ...', function() { // this function executes when any of the myHealthN attributes change }); Once the event fires, the sheet worker script generally needs to get the value of those attributes, and occasionally the values of other attributes as well. This is done with the getAttrs function: on('change:myHealth0 change:myHealth1 change:myHealth2 ...', function() { getAttrs(['myHealth0', 'myHealth1', 'myHealth2', ...], function(values) { // values.myHealth0 will be the value of the myHealth0 attribute, values.myHealth1 will be myHealth1, etc. }); }); Finally, the sheet worker generally needs to set the value of some attributes in order to do anything useful. This is done using the setAttrs function: on('change:myHealth0 change:myHealth1 change:myHealth2 ...', function() {
getAttrs(['myHealth0', 'myHealth1', 'myHealth2', ...], function(values) { var newMyHealth = values;
// do stuff. let's say we sort the myHealth values like a priority queue so aggravated values have highest priority // and get shifted over to the myHealth0, etc, while bashing and undamaged have the lowest priority and get shifted // over to the myHealth10, etc. setAttrs({ myHealth0: newMyHealth.myHealth0, myHealth1: newMyHealth.myHealth1, myHealth2: newMyHealth.myHealth2, ... });
});
}); Also, as a side note, JSFiddle has three separate panes for source code; the top-left is intended for HTML only, and the bottom-left is intended for JavaScript only. As you've demonstrated, you can certainly put a <script> block in the HTML pane, but separating the two makes fiddles easier to read. =)