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

Token gmnotes and A-Synchronicity

Admittedly I do not understand asynchronous stuff. I am wanting to store a small array on a token (of tokenIDs basically), then be able to access it and modify it then replace it within the script. I had thought of using gmnotes to do so, but the asynchronous .get seems to cause me issues. Is there a way around this? - maybe have it delay a function until the gmnotes has 'arrived' or is there an alternate field (i didnt want to use bar values though) suggested? These tokens do not have unique character sheets associated with them. Thanks for input/thoughts.
1614056685
The Aaron
Roll20 Production Team
API Scripter
GM Notes on tokens are not Asynchronous, only GM Notes (and Notes and Bio) on Characters and Handouts are Asynchronous. So, you can just grab the contents and set them like other properties: let gmnotes = token.get('gmnotes'); token.set('gmnotes', `Foo: ${gmnotes}`); One thing to be aware of is that GM Notes are encoded.  If you typed "Bunches of things." in the GM Notes field of a token, then read it with the API, it would look like: "%3Cp%3EBunches%20of%20things.%3C/p%3E" The editor inserts HTML elements, and the whole string is escaped.  You can decode it with unescape(), and reencode it with escape(), so the above would reasonably be rewritten as: let gmnotes = unescape( token.get('gmnotes') ) ; token.set('gmnotes', escape( `Foo: ${gmnotes}`) ) ; Hope that helps!
It did, thanks. I think my issue was that I was treating gmnotes as a variable of definable type and trying to put an actual array in there, rather than as a string/text. The light bulb went on when you mentioned encoding. Anyways, problem solved, actually opened up other thoughts/uses for that field, and all is good!
1614134718
The Aaron
Roll20 Production Team
API Scripter
Woot!  Glad to hear it!