Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Modify GM Notes

Hey there, i am not sure whats going wrong here. Somehow I end up in an infiite loop which causes a stack overflow: I want to modify the GM Notes of a character.  character.get("gmnotes", function(notes){ var newNotes = notes + " test"; log(newNotes); character.set("gmnotes", newNotes); }); The log is fine, but whenever I call the character.set it seems to do some kind of recursive behaviour. "Note test test" "Note test test test" "Note test test test test" "Note test test test test test" "Note test test test test test test" "Note test test test test test test test" "Note  test test test test test test test test" "Note test test test test test test test test test" "Note test test test test test test test test test test" RangeError: Maximum call stack size exceeded RangeError: Maximum call stack size exceeded     at new Uint8Array (<anonymous>)     at new FastBuffer (internal/buffer.js:950:1)     at createUnsafeBuffer (buffer.js:149:12)     at createPool (buffer.js:157:15)     at allocate (buffer.js:413:7)     at Function.allocUnsafe (buffer.js:384:10)     at Client._sendFrame (/home/node/d20-api-server/node_modules/websocket-driver/lib/websocket/driver/hybi.js:243:25)     at Client.onMessageReady (/home/node/d20-api-server/node_modules/websocket-driver/lib/websocket/driver/hybi.js:225:12)     at Client.<anonymous> (/home/node/d20-api-server/node_modules/websocket-driver/lib/websocket/driver/hybi.js:231:24)     at pipe (/home/node/d20-api-server/node_modules/websocket-extensions/lib/pipeline/index.js:37:40) Thanks for your help, Kerubis
1617642168
The Aaron
Roll20 Production Team
API Scripter
There's a bug/race condition with setting the bio, gmnotes, and handout fields on characters and handouts.  To avoid it, you need to do the setting outside the function that did the getting.  The easiest way to do that is with a 0 delayed timeout: character.get("gmnotes", function(notes){ var newNotes = notes + " test"; log(newNotes); setTimeout( ()=>character.set("gmnotes", newNotes) ,0); }); Here I'm deferring the set to outside the callback function's callstack by delaying it to the next timeslot.
Works perfectly fine, thank you.