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

Persistant Variables?

Is there any way to get a truly persistent API value or array to remain, even after the sandbox shuts down to inactivity? I was thinking a journal item could hold the values, but before I rig something up I thought I'd check to make sure the feature doesn't exist somewhere that I'm implementing. I am currently writing a calendar tool to track the current date and time of day in our campaign. I already have everything in place to increment and manage time as we play, but I don't have any sure-fire way to save the current datetime information in between sessions. So far I have everything saved in a global variable in the API, but I don't know if those will clear when the sandbox shuts down. Any ideas?
Make a calendar journal and store the data as attributes.
1411229850

Edited 1411230682
The Aaron
Roll20 Production Team
API Scripter
Use the state object. That's what it's for. It's persisted to database every 5 seconds or so, and thus is always there. Be sure to namespace your data, I use the name of my script as the sub-object name. All my scripts have a function called checkInstall() that verifies the existence of the sub object at startup (in on('ready',..). I add a property with a version so that if I update the way I store things, I can change the schemaVersion and the script can overwrite the existing one if it's not correct (or modify it if I ever have a case where I want to preserve the existing data). Here's my basic layout: var BaseScript = BaseScript || (function() { 'use strict'; var version = 0.2, schemaVersion = 0.1 , checkInstall = function() { if( ! _.has(state,'BaseScript') || state.BaseScript.version !== schemaVersion ) { state.BaseScript = { version: schemaVersion , otherthing: 'some value' }; } ), HandleInput = function(msg) { var args, turnorder; if (msg.type !== "api" || !isGM(msg.playerid) ) { return; } args = msg.content.split(/ +/); switch(args[0]) { case '!something': // access other thing state.BaseScript.otherthing='whatever'; break; } }, RegisterEventHandlers = function() { on('chat:message', HandleInput); }; return { RegisterEventHandlers: RegisterEventHandlers, CheckInstall: checkInstall }; }()); on("ready",function(){ 'use strict'; if("undefined" !== typeof isGM && _.isFunction(isGM)) { BaseScript.CheckInstall(); BaseScript.RegisterEventHandlers(); } else { log('--------------------------------------------------------------'); log('BaseScript requires the isGM module to work.'); log('isGM GIST: <a href="https://gist.github.com/shdwjk/8d5bb062abab184636" rel="nofollow">https://gist.github.com/shdwjk/8d5bb062abab184636</a>... log('--------------------------------------------------------------'); } });
TY for the answers. I'll try them out when I have a little bit more time.