configuring mod Options with a dedicated Mods tab

Update 1.3.0 changed the Options screen in a way that is breaking this code. to work around the problem, you can add this block to your -options.js script before calling Options.addInitCallback for the first time. i've also sent this to the Firaxis community team to let the devs know that this is a pain point for modders.

JavaScript:
// fix Options initialization
Options.addInitCallback = function(callback) {
    if (this.optionsReInitCallbacks.length && !this.optionsInitCallbacks.length) {
        throw new Error("Options already initialized, cannot add init callback");
    }
    this.optionsInitCallbacks.push(callback);
    this.optionsReInitCallbacks.push(callback);
}
 
Update 1.3.0 changed options initialization in a way that locks out all changes after the first set (which contains the vanilla options). tbh i think that's a bug, just one that doesn't affect vanilla because it initializes all options in one go. you can fix that by patching Options with this code, before calling Options.addInitCallback

JavaScript:
// fix Options initialization
Options.addInitCallback = function(callback) {
    if (this.optionsReInitCallbacks.length && !this.optionsInitCallbacks.length) {
        throw new Error("Options already initialized, cannot add init callback");
    }
    this.optionsInitCallbacks.push(callback);
    this.optionsReInitCallbacks.push(callback);
}

however, it's a huge compatibility risk for multiple mods to patch the same vanilla method. i've reported the bug to Firaxis, but it's probably not a high priority for them to fix a bug that only affects modders. unfortunately i can't recommend adding Options to new mods until they fix it.
 
Last edited:
Back
Top Bottom