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

[Script] Store JS Objects as JSON in Roll20 Objects

1367340625
Alex L.
Pro
Sheet Author
I made this script so i can save and load data into objects to be used as session data that percists. Very Beta (like the API), demo code included. Set debug to false to remove debug messages. <a href="https://gist.github.com/pigalot/5490005?8" rel="nofollow">https://gist.github.com/pigalot/5490005?8</a>
This is a neat idea. Two things I'll say: 1) This may not work so well, since the GM Notes field has some formatting that's applied to it whenever you save the Character. So the data in that field could easily get destroyed if you open up the Character and click "save". 2) In addition to the global "state" object being persisted, I'm considering adding a special property on each object that is specifically to be used to store information by API scripts. Do you think it makes more sense to just let people use the sate variable (e.g. state[token.id] = {}) or to have a specific per-object property? Glad that you're diving in! :-)
Neat idea to use the journal as a JSON storage area. I can already see using it as a way to pick out which tokens are party members and which aren't.&nbsp;
1367342738
Alex L.
Pro
Sheet Author
Riley D. said: This is a neat idea. Two things I'll say: 1) This may not work so well, since the GM Notes field has some formatting that's applied to it whenever you save the Character. So the data in that field could easily get destroyed if you open up the Character and click "save". 2) In addition to the global "state" object being persisted, I'm considering adding a special property on each object that is specifically to be used to store information by API scripts. Do you think it makes more sense to just let people use the sate variable (e.g. state[token.id] = {}) or to have a specific per-object property? Glad that you're diving in! :-) I just made this as a quick temp workaround, but I will double check I don't get any errors when saving the roll20 obj from in roll20. I think a simple hidden text field called apidata or something on every object would be more than enough storage for what most people need, although it would be nice to have the state to store more global things and a field for each object to store things just relating to it. I’m just working on a way to let multiple scripts save to the same object without overriding.
1367344993
Alex L.
Pro
Sheet Author
Update: Updated to let multiple scripts save to the same object and fixed problem of formatting in notes. Added error handling for when objects not found, normally because names are caps sensitive
Nice script. I do love the idea of having state per graphic, so that would be great to have as well.
1367403351
Alex L.
Pro
Sheet Author
Update: Test code removed. Fixed even more formating promblems. Lots more Error handeling. Can now accept the roll20 object directly.