MV How do you set a switch's default value in YEP Option Core?

Hi,
So I noticed a problem after a test deployment of my game. With the config.rpgsave wiped for the deployment I was able to catch a problem with my options menu.

All of the options are currently displaying the correct default setting, however, upon checking the appropriate switches in game, it did not actually set the switch correctly in game. I don't know what I am doing when it comes to coding, but I've played around with a few things to see if I could fix this to no avail. I've been googling the past couple hours to see if I could get this solved, but I'm really just at my wits end.

To clarify: The options are working correctly. However the default - first launch - setting is improperly set. On first launch, the option DISPLAYS "on" but in game, it is clearly not set to "on".

I was just launching a beta test for play testers when I encountered this problem, so I guess I am sort of in a rush on this:LZSskeptic: So, I'm basically groveling on my hands and feet now, please help me fix this.

Here is one options menu item as an example:
Option1.jpg

option2.jpg


Here is all of the code that makes up the specific option shown above (but to be clear, there are other switch-based options that are also not working properly either.) Between each screen shot I didn't change any options in the menu. This is simply to display what the game *thinks* the default setting is.

Code:
//Make Option Code
this.addCommand(name, symbol, enabled, ext);

//Draw Option Code
var rect = this.itemRectForText(index);
var statusWidth = this.statusWidth();
var titleWidth = rect.width - statusWidth;
this.resetTextColor();
this.changePaintOpacity(this.isCommandEnabled(index));
this.drawOptionsName(index);
this.drawOptionsOnOff(index);

//Process OK Code
const index = this.index();
const symbol = this.commandSymbol(index);
const value = this.getConfigValue(symbol);
this.changeValue(symbol, !value);

const catalyst = $gameSwitches.value(182);
if (catalyst) {
  $gameSwitches.setValue(182, false);
} else {
  $gameSwitches.setValue(182, true);
}

//Cursor Right Code
var index = this.index();
var symbol = this.commandSymbol(index);
var value = this.getConfigValue(symbol);
this.changeValue(symbol, true);
$gameSwitches.setValue(182, true);

//Cursor Left Code
var index = this.index();
var symbol = this.commandSymbol(index);
var value = this.getConfigValue(symbol);
this.changeValue(symbol, false);
$gameSwitches.setValue(182, false);

//Default Config Code
ConfigManager[symbol] = true;

//Save Config Code
config[symbol] = ConfigManager[symbol];

//Load Config Code
var value = config[name];
if (value !== undefined) {
   ConfigManager[name] = value;
} else {
   ConfigManager[name] = true;
}

Just for fun, here is a different option in my menu that is also switch-based. It is also not working correctly (all of my switch-based options are not working correctly)
Spoiler
Code:
//Make Option Code
this.addCommand(name, symbol, enabled, ext);

//Draw Option Code
var rect = this.itemRectForText(index);
var statusWidth = this.statusWidth();
var titleWidth = rect.width - statusWidth;
this.resetTextColor();
this.changePaintOpacity(this.isCommandEnabled(index));
this.drawOptionsName(index);
var value = this.getConfigValue(symbol);
var rate = (50).clamp(0, 1);
if (value === true) {
var gaugeColor1 = this.textColor(11);
var gaugeColor2 = this.textColor(11);
} else {
var gaugeColor1 = this.textColor(23);
var gaugeColor2 = this.textColor(23);
}
this.drawOptionsGauge(index, rate, gaugeColor1, gaugeColor2);
this.drawText(" ", titleWidth, rect.y, statusWidth, 'center');
this.drawOptionsOnOff(index, "Enabled", "No Free Healing");

//Process OK Code
const index = this.index();
const symbol = this.commandSymbol(index);
const value = this.getConfigValue(symbol);
this.changeValue(symbol, !value);

const catalyst = $gameSwitches.value(16);
if (catalyst) {
  $gameSwitches.setValue(16, false);
} else {
  $gameSwitches.setValue(16, true);
}

//Cursor Right Code
var index = this.index();
var symbol = this.commandSymbol(index);
var value = this.getConfigValue(symbol);
this.changeValue(symbol, true);
$gameSwitches.setValue(16, true);

//Cursor Left Code
var index = this.index();
var symbol = this.commandSymbol(index);
var value = this.getConfigValue(symbol);
this.changeValue(symbol, false);
$gameSwitches.setValue(16, false);

//Default Config Code
ConfigManager[symbol] = true;

//Save Config Code
config[symbol] = ConfigManager[symbol];

//Load Config Code
var value = config[name];
if (value !== undefined) {
   ConfigManager[name] = value;
} else {
   ConfigManager[name] = true;
}

Your help is greatly appreciated.

edit:
:LZSteary: I'm so lost on this...I have continued googling and just testing random stuff to see if I can fix this. The thing that has me the most confused is that others have asked about setting the default to ON before, and the code used (in the Load Config Code) is exactly the same as my code. So what is going wrong?
I tried moving the plugins around - I moved them around a lot, but nothing.
I've tried adjusting my load config code and default config code. I double checked the switch value in the code and made sure it is correct.
What do I do? Someone please save me.

edit:
Here is my entire plugin list (I moved all of Yanfly's plugins to the "proper" order sometime after this screen shot was taken. It did not fix the problem.) The screen shot was taken a few days ago intended to serve a different purpose, that's why there is highlighted plugins. For this thread on Options Core, please ignore the highlighted text.
Spoiler
PluginList.jpg

I have turned off plugins to see if there are any conflict. The ones I have turned off so far are:
Galv Custom Title, Galv MenuFade, DhoomTitleExit; SRD SuperToolsEngine, HUDMaker, and BattleLogUpgrade. So far, none of these have fixed the problem.

I swear in the past this used to work correctly, then again, it's so hard to say if I am just misremembering things. At some point I upgraded NWJS. Do you think upgrading NWJS might have broken the plugin?
const catalyst = $gameSwitches.value(182);
if (catalyst) {
$gameSwitches.setValue(182, true);
} else {
$gameSwitches.setValue(182, false);
}
This is backwards.

You're saying "if the value of 182 is true, make it true, otherwise make it false."

The conditional should read if (!catalyst)

Or you could make the whole thing shorter, delete everything you typed that I quoted, and just put
Code:
$gameSwitches.setValue(182, !$gameSwitches.value(182));

There's really no purpose in a variable that only gets typed out once after its declaration. You'd save keystrokes by never creating it 😉
Thanks for pointing that out, though I believe that mistake happened when I was trying random things to get this to work properly.
Unfortunately this doesn't address the issue I am having, just a mistake I had created while trying to figure out the issue.
Thanks for pointing that out, though I believe that mistake happened when I was trying random things to get this to work properly.
Unfortunately this doesn't address the issue I am having, just a mistake I had created while trying to figure out the issue.
So does the code that ATT_Turan gave you not work?
It does not.

edit:
to clarify, it works fine at the function it is intended to serve: turning the switch on or off when the player pushes the OK key. But the problem I am trying to fix is when the game first boots, it needs to already have turned on specific switches. The code he provided does not determine defaults (afaik).
Suggestions:
  1. Process OK:
    JavaScript:
    var index = this.index();
    var symbol = this.commandSymbol(index);
    var value = this.getConfigValue(symbol);
    this.changeValue(symbol, !value);
    $gameSwitches.setValue(182, !value);
    I.e. set the switch to the same value as you just set the config value.

  2. Load Config:
    JavaScript:
    var value = config[symbol];
    if (value !== undefined) {
       ConfigManager[symbol] = value;
    }
    $gameSwitches.setValue(182, ConfigManager[symbol]);
    I.e.
    • Use symbol, not name;

    • Default gets applied before Load, so there's no need to set a default in the Load code if the file data is undefined;

    • Update the switch so it matches the resultant config setting. This is important because otherwise the switch will start in the OFF state (false), which doesn't match your default setting (true).
(You'll also need a plugin to make switch values persist through New Game & Continue, but from the "<Global Meta>" switch name prefix I'm guessing you've already got one.)
Is the code you shared only a partial replacement for the existing code or does it replace the existing code entirely?
After replacing the code in each section, I am getting a crash now.

Crash.png
Oh, yea, that's unfortunate. By default the game loads the options before initialising game data (like $gameSwitches). So I think you may need a workaround.

A couple of ideas:
  1. Change your settings so that they all have a default value of false. Switches all start as false by default, so I think that should eliminate that particular problem. This would mean you'd have to invert the display/checks: the switch is on when the setting is off and vice versa.

  2. Alternatively, swap the in-game switch 182 check(s) with Conditional Branch -> Script:

    ConfigManager["alwaysDash"]
    Replace alwaysDash with whatever the symbol is for your config setting. Obviously, this only works if you're checking it in a Conditional Branch, rather than an event page condition or something. It would mean you don't need to try to sync a game switch with the setting, though!
I appreciate your work arounds for this problem. I would really prefer to get this fixed right, but at the very least this got me thinking...
Would it be possible to just deploy the game, launch the game and preconfigure the options, then distribute the game?
I've already tested this and it seems to work, but I guess I am wondering is this machine-specific? I know it's likely not since the config.rpgsave file is contained within the game's folder, but I just want to be 100% sure that if I were to pre-configure the options, would these persist on other people's computers?
Would it be possible to just deploy the game, launch the game and preconfigure the options, then distribute the game?
Yes, that should work for a standalone deployment. 👋

It wouldn't work for web-deployment, because in that case the saves are stored in the local storage of the player's browser.

Note that if the player manually deletes the save folder or config file, they will still see this bug.
Okay, then I suppose that will work for now.
Maybe in the future I will revisit this problem and try to find a proper solution to it. Or I may just put a file in the save folder warning players not to delete the config file. I don't expect many players to go there anyways. Anyways, I guess this can be closed for now...though I hesitate to change the title to "solved" since...It's more like it had a bandaid applied.
wouldn't it be better if OFF = showin the indicator and ON disable it?
like, do you want to disable the indicator? ON = turning them off?

Original thread: https://forums.rpgmakerweb.com/threads/how-do-you-set-a-switchs-default-value-in-yep-option-core.152826/