After some further testing, I'm pretty certain this is related to the eventinfo based sheet workers. Here's a repro sheet and script: <div>
<div>
<label for="attr_base">Base Value</label>
<!-- <input type="text" name="attr_base" value="0" title="Base Value" /> -->
<input type="number" name="attr_base" step="1" min="0" max="6" value="0" title="Base Value" />
</div>
<div>
<label for="attr_derived">Derived Value</label>
<input type="text" name="attr_derived" value="0" title="Derived Value" />
</div>
<div>
<label for="attr_base2">Base Value 2</label>
<!-- <input type="text" name="attr_base2" value="0" title="Base Value" /> -->
<input type="number" name="attr_base2" step="1" min="0" max="6" value="0" title="Base Value" />
</div>
<div>
<label for="attr_derived2">Derived Value 2</label>
<input type="text" name="attr_derived2" value="0" title="Derived Value 2" />
</div>
</div>
<div>
<button type='roll' value="!repro-setwithworker @{character_id}" name="roll_repro">Test</button>
</div>
<script type="text/worker">
on('change:base',()=>{
console.log(`%c[One] Change to attribute: %cbase`,'background-color:#ffcccc;','color:#339933;font-weight:bold;');
getAttrs(["base"], (attrs)=>{
setAttrs({
derived: (attrs.base * 3)
});
});
});
on("change:base2", function(eventinfo) {
console.log(`%c[Two] Change to attribute: %cbase2`,'background-color:#ffcccc;','color:#339933;font-weight:bold;');
console.log(JSON.stringify(eventinfo));
const newValue = parseInt(eventinfo.newValue) || 0, previousValue = parseInt(eventinfo.previousValue) || 0;
let update = {
derived2: `${previousValue} => ${newValue}`
};
setAttrs(update, {silent: true});
});
</script>
on('ready',()=>{
on('chat:message',(msg)=>{
if('api'===msg.type && /^!repro-setwithworker\b/i.test(msg.content)){
let args = msg.content.split(/\s+/);
let c = getObj('character',args[1]);
if(c){
let a = findObjs({
type: 'attribute',
name: 'base',
characterid: c.id
})[0];
if(a){
let newValue = (1+a.get('current'))%7;
a.setWithWorker({
current: newValue
});
sendChat('Repro',`Set <code>base</code> to <code>${newValue}</code>`);
}
let a2 = findObjs({
type: 'attribute',
name: 'base2',
characterid: c.id
})[0];
if(a2){
let newValue = (1+a.get('current'))%7;
a2.setWithWorker({
current: newValue
});
sendChat('Repro',`Set <code>base2</code> to <code>${newValue}</code>`);
}
}
}
});
});
eventinfo structures that are issued in the API do not have a triggerName, previousValue, and newValue property. In the above, that results in the Derived Value 2 field being updated incorrectly. In many cases, particularly if you do it more than once, it will appear that nothing is being updated (and depending on how the sheet worker uses the value, nothing may be updated). There is an additional strange occurrence when you switch from a change on the character sheet to a change from the API. In the above, if you manually change the Base Value 2, you can see an event in the local console log for the change. If you then click the Test button, you'll see another event in the local console log for the API change (missing the newValue property) as well as an event in the API Output Console which is missing all 3 properties from above. Subsequent API changes will not cause an event in the local console log. One other interesting thing I learn in the foray is that a change to a character sheet does not automatically cause a change to the sheetworkers loaded in the API sandbox, which means you should restart your sandbox if you install a new character sheet. Probably that isn't a major concern for most people, but if you're developing a character sheet and an API script, you'd need to be aware of that.