OK, I have been using the minimal code provided by Chris D, and I can confirm that I could see the abnormal behaviour I was referring to.
Follow Chris D's link for reference of the minimal code, but here is a summary of how it works:
3 attributes i1, i2, i3.
on( change:i1 change i2 change i3) sheetworker that logs any change of value of i1, i2 or i3.
on("change:attribute") API function that logs any change to any attribute, but also if there is a change of value of i2, will copy its value to i3.
A button on the sheet sends a command to the API to change the value of i2.
I will not add to the bugs reported by Chris on the other thread, but come back to my bug about double datalogging/double triggering
How it should behave
If a change of i2 is done manually, it should result in:
- Change of i2 ( from the sheetworker event) logged in browser console
- Change i2 ( from the API event ) logged in API console
- API changes the i3 value to match i2
- Change i3 ( from the sheetworker event, but triggered by the API setwithworker ) logged in the API console
- Change i3 (from the API event ) also logged in the API console
If a change of i2 is done via the API button it should result in:
- Change of i2 ( from the sheetworker event, triggered by the API setwithworker) logged in API console
- Change i2 ( from the API event ) logged in API console
- API changes the i3 value to match i2
- Change i3 ( from the sheetworker event, but triggered by the API setwithworker ) logged in the API console
- Change i3 (from the API event ) also logged in the API console
How it behaves Sequence 1
- Create a Brand new character
- Change 1 : Change the i2 value manually to 1.
- As already reported by Chris, on this first change, only i2 changes and this change is logged in the browser console. API event doesn't fire
Browser console
Sheetworker i2 triggered
{"sourceAttribute":"i2","sourceType":"player","triggerName":"i2","newValue":"1"}
- Change 2: change i2 a second time manually to 2
- As reported by Chris, this is mostly as planned, except that the sheetworker event for i3 in the API console is triggered twice ( for the CreateObj and for the setwithworker) - Also the log says value of i3 has been set to 20 then to 2... but it doesn't display
Browser Console
Sheetworker i2 triggered
{"sourceAttribute":"i2","sourceType":"player","triggerName":"i2","previousValue":"1","newValue":"2"}
API Console
{"name":"i2","current":"1","max":"","_id":"-OM951m8IHZ5JWg2-Zfz","_type":"attribute","_characterid":"-OM94yNaD_7ivpVafC_c"}
{"name":"i2","current":"2","max":"","_id":"-OM951m8IHZ5JWg2-Zfz","_type":"attribute","_characterid":"-OM94yNaD_7ivpVafC_c"}
"API i2 triggered"
"Sheetworker i3 triggered"
"{\"sourceAttribute\":\"i3\",\"sourceType\":\"api\",\"triggerName\":\"i3\",\"newValue\":20}"
"Sheetworker i3 triggered"
"{\"sourceAttribute\":\"i3\",\"sourceType\":\"api\",\"triggerName\":\"i3\",\"previousValue\":20,\"newValue\":\"2\"}"
![]()
- Change 3 : Click manually i3 to 3
- Note that the Browser console has no PreviousValue, and the API Console doesn't even trigger
Browser Console
Sheetworker i3 triggered
{"sourceAttribute":"i3","sourceType":"player","triggerName":"i3","newValue":"3"}
- Change 4 : Change Manually i3 to 4
- This time there is a previousvalue in the browser console, and the API Console triggers correctly
Browser Console
Sheetworker i3 triggered
sheetsandboxworker.js:155 {"sourceAttribute":"i3","sourceType":"player","triggerName":"i3","previousValue":"3","newValue":"4"}
API Console
{"name":"i3","current":"3","max":"","_id":"-OM95uRVnOZMam1K3WgV","_type":"attribute","_characterid":"-OM94yNaD_7ivpVafC_c"}
{"name":"i3","current":"4","max":"","_id":"-OM95uRVnOZMam1K3WgV","_type":"attribute","_characterid":"-OM94yNaD_7ivpVafC_c"}
- Change 5 : Use the API button to change i2 to 5
- The change of i2 is done and triggers sheetworker in API Console, but there is not the subsequent trigger that would copy i2 in i3
API COnsole
{"content":"!demo~ -OM94yNaD_7ivpVafC_c~ 5","playerid":"-MT8xhgWaPwyKrQf-hV0","rolledByCharacterId":"-OM94yNaD_7ivpVafC_c","type":"api","who":"Jiboux (GM)"}
{"name":"i2","current":"2","max":"","_id":"-OM951m8IHZ5JWg2-Zfz","_type":"attribute","_characterid":"-OM94yNaD_7ivpVafC_c"}
"Sheetworker i2 triggered"
"{\"sourceAttribute\":\"i2\",\"sourceType\":\"api\",\"triggerName\":\"i2\",\"previousValue\":\"2\",\"newValue\":\"5\"}"
- Change 6 : Change manually i2 to 6
- Change i2 is logged in the Browser Console as it should be, and API detects the change of i2, and copies i3, as it should be... BUT BUT BUT : the sheetworker change detection of i3 is both in the Browser console (sourceType:player) and API Console (sourceType:API), where the change being done by setwithworker it should only be in the API
- Note also that the findObjs has found several instances of i3 when trying to copy i3, one with value 2, and one with value 4. The one with value 2 is likely the one in change 2 that was never displayed.
Browser Console
Sheetworker i2 triggered
{"sourceAttribute":"i2","sourceType":"player","triggerName":"i2","previousValue":"5","newValue":"6"}
Sheetworker i3 triggered
{"sourceAttribute":"i3","sourceType":"player","triggerName":"i3","previousValue":"2","newValue":"6"}
API Console
{"name":"i2","current":"5","max":"","_id":"-OM951m8IHZ5JWg2-Zfz","_type":"attribute","_characterid":"-OM94yNaD_7ivpVafC_c"}
{"name":"i2","current":"6","max":"","_id":"-OM951m8IHZ5JWg2-Zfz","_type":"attribute","_characterid":"-OM94yNaD_7ivpVafC_c"}
"API i2 triggered"
"2025-3-24 21:48:40 (UTC) Error Earthdawn:findOrMakeObj() found 2 objects: "
[{"name":"i3","current":"2","max":"","_id":"-OM95MbQUy64U5ur6eiq","_type":"attribute","_characterid":"-OM94yNaD_7ivpVafC_c"},{"name":"i3","current":"4","max":"","_id":"-OM95uRVnOZMam1K3WgV","_type":"attribute","_characterid":"-OM94yNaD_7ivpVafC_c"}]
"removing attr[ 1 ] and keeping attr[ 0]."
"Sheetworker i3 triggered"
"{\"sourceAttribute\":\"i3\",\"sourceType\":\"api\",\"triggerName\":\"i3\",\"previousValue\":\"2\",\"newValue\":\"6\"}"
- Change i7 : Change manually i2 to 7
- This subsequent change seems to still have the issue of i3 reported on both consoles; even if the duplicate attribute stuff has disappeared
Browser Console
Sheetworker i2 triggered
{"sourceAttribute":"i2","sourceType":"player","triggerName":"i2","previousValue":"6","newValue":"7"}
Sheetworker i3 triggered
{"sourceAttribute":"i3","sourceType":"player","triggerName":"i3","previousValue":"6","newValue":"7"}
API Console
{"name":"i2","current":"6","max":"","_id":"-OM951m8IHZ5JWg2-Zfz","_type":"attribute","_characterid":"-OM94yNaD_7ivpVafC_c"}
{"name":"i2","current":"7","max":"","_id":"-OM951m8IHZ5JWg2-Zfz","_type":"attribute","_characterid":"-OM94yNaD_7ivpVafC_c"}
"API i2 triggered"
"Sheetworker i3 triggered"
"{\"sourceAttribute\":\"i3\",\"sourceType\":\"api\",\"triggerName\":\"i3\",\"previousValue\":\"6\",\"newValue\":\"7\"}"
What it shows beyond the bugs reported by Chris
- It seems there is somehting going on with the initialization of attributes. it looks like When a character is just created, and until some attributes are actually written by the player for the first time, the synchronization of value between the API and the client side is failing.
- This failed synchronization seems to create a lack of detection on the API side of a change on the player side
- This failed synchronization also seems to create that a value changed on API side doesn't display on browser side
- Finally, I can't really build the exact sequence why it is only on change 6, and on none of the others that there is this bug I initially reported of having the double datalogging, but once it is double logged, it seems subsequent changes still double log...
Hope this is useful