#Initialization Script
1 messages · Page 1 of 1 (latest)
I agree, but it may be my only option if it proves to be impossible to force a reset of the default. That also would reset the version number for the last update, causing modules to reset unnecessarily, as well.
Right now, the modules try to re-initialize if they've been updated since the last time the scripts ran.
This is roughly what I had in mind:
function getModuleDefault({systemVersion = 0.1.0, moduleVersion = 1.0}) {
return {
loaded: false,
asked: false,
systemVersion,
moduleVersion,
};
};
function initDefault(packs) {
const rv = {};
for (const p of packs) {
rv[p] = getModuleDefaut();
}
return rv;
}
const packs = ['pack1', 'pack2'];
game.settings.register('earthdawn4e', 'packsInitialized', {
scope: 'world',
type: Object,
default: initDefault(packs),
config: false,
});
const packcfg = game.settings.get('earthdawn4e', 'packsInitialized');
let updateNeeded = false;
// Fill in missing packs
for (const p of packs) {
if (packcfg[p] === undefined) {
packcfg[p] = getModuleDefault();
updateNeeded = true;
}
}
if (updateNeeded) game.settings.set('earthdawn4e', 'packsInitialized', packcfg);
Without the typoes and stuff.
This worked! Thank you sooooooo much. You have no idea how long I've been struggling with that.