Advertisement Create a free account

Async notes/gmnotes don't work immediately after creation

1462624609
Lucian
Pro
API Scripter
Testcase: on('chat:message', msg => {     if(msg.type === 'api' && msg.content === '!test') {         const handout = createObj('handout', {name: 'test', notes:'testNotes'}); log(handout);         handout.get('notes', notes => handout.set('notes', notes + 'extra'));      } }); I would expect that running !test would create a handout with the text 'testNotes' and then immediately append 'extra' to the text. In practice, this breaks in two ways. First of all (and this is behaviour that I've seen in other scripts as well), the resulting text of the handout is 'nullextra', and the log output shows that the handout actually has the notes populated directly on the object after creation. This remains true for objects created with a notes attribute even if you restart the API and get the object back by id - it is permanently incorrect. As soon as you call .set('notes', value), however, the contents of the notes field are removed and replaced with a number, and from then onwards can only be accessed asynchronously. Obviously this inconsistency is rather unhelpful. The second problem is that the script above actually crashes the API : RangeError: Maximum call stack size exceeded RangeError: Maximum call stack size exceeded at $a.t.remove (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:26:18) at $a.t.remove (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:26:133) at $a.t.remove (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:26:392) at $a.t.remove (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:26:392) at Ua.t.remove (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:21:402) at O.t.J (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:40:559) at O.t.Ba (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:40:752) at O.t.Ba (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:40:728) at U (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:92:256) at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:108 I'm not sure what the exact criteria are for the crash - my testcase produces it reliably - but it appears incidental to the other issue.
1462825889

Edited 1462825930
Phil B.
Roll20 Team
First off, I would like to thank you for the really short and "works(or doesn't work, depending on how you look at it) when I copy and paste it into a game" API code. It makes testing everything a whole lot easier for me, I really appreciate it.  Anyways, about the actual issue: It looks like setting the notes/gmnotes from the createObj function is being really weird. It's obviously setting the notes, they show up in the log() info correctly. But, if you comment out the .set line, the notes in the actual handout are totally blank. This blank, or broken, value is what you're getting from the .get call, hence null. As for the error you're receiving, it looks like we've got an infinite loop, or something similar, happening behind the scenes when you try to set the value inside of the callback function. This happens even with a regular function in place of the lambda function. Thanks for pointing this out, and thanks again for the easy testing material. I've created a bug report for this, and one of us will take a look at it as soon as we get a chance.
1462828027
Lucian
Pro
API Scripter
Cool. It's nice when you occasionally get a bug with a simple reproduction path and can post a clear testcase, rather than just "I sometimes see some weird stuff when I do something a bit like this but I can't always make it happen"  :-) It's not particularly critical for me, since there's an easy workaround - use .set instead of passing the value to createObj. I've made a note on the relevant section of the wiki about this to save others running into trouble - it would be great if someone could remove it when the issue gets fixed as well.
1462829861
Phil B.
Roll20 Team
Thanks for letting me know about the wiki, I'll note in the bug that it's there so we know to remove it once it's fixed.