
It's not unusual for a character sheet to have multiple places that display the same value. One of these will be the primary place for it to be edited, while others will display it. The main editing field will have a default value defined, but the other displays will just reference the attribute. Take the following stub character sheet:
<input type="number" name="attr_baseattribute" value="8">
<span name="attr_baseattribute"></span>
<input type="number" name="attr_depattribute" />
<input type="text" name="attr_triggerattribute"/>
<script type="text/worker">
console.info("Hello from sheetworker");
on("change:triggerattribute", function() {
console.info("Trigger attribute heard change");
getAttrs(['baseattribute'], function(vals) {
console.info('Base attribute value: ' + vals.baseattribute);
setAttrs({depattribute:vals.baseattribute});
});
});
</script> If I manually create a character and edit the triggerattribute field, I get the expected behaviour - the value of depattribute gets set to the default value of baseattribute (in this case 8), and the text 'Base attribute value: 8' is output to the log. If, however, I add the following API script: on('chat:message', function(msg) {
'use strict';
if (msg.content === '!test') {
const char = createObj('character', {name:'test'});
const attribute = createObj('attribute', { name:'triggerattribute', characterid:char.id});
attribute.setWithWorker({current:'foo'});
}
}); and then trigger it from chat, the dependent attribute gets set to the empty string, and the log output reads 'Base attribute value: '. If I remove the extra span from the character sheet html it works correctly, even under the API, so it looks like whatever is scanning the sheet for default values for the API sheetworkers is getting thrown by the presence of multiple fields for the same attribute (even though only one defines a default) when the equivalent code for the client handles this without problems. This is breaking some stuff for the 5e shaped sheet/script, so if it's not a hard problem it would be good to have a fix so we can take advantage of the API sheetworkers feature properly. Thanks!