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('--------------------------------------------------------------');
}
});