MV [SOLVED] YEP Options Core: How to make Show/Hide code work?

I am wondering if it's possible to show or hide certain options via a switch. For example: I might want some options that can be accessed from the main menu, but once the game is loaded, those options are no longer visible.

I'm no coding expert, I just fired blind with this little code in hopes it might work but I genuinely have no idea.

Code:
if ($gameSwitches.value[39] === true) {
show = false;
} else {
show = true;
}
(Switch #39 is a switch that is used to determine when the player is...well...playing the game)

Testing the game, no errors are given so I don't think my code's syntax is wrong...but, it also doesn't function....like....at all. Before activating switch 39, the options are visible in the options menu. Once activating switch 39...the options are still visible in the options menu.

Any ideas?

(In case you missed the title of the thread: this is pertaining to YEP Options Core)
It should be $gameSwitches.value(39) instead of $gameSwitches.value[39]

You could also further shorten it to $gameSwitches.value(39) ? show=false : show=true
Or simply show = !$gameSwitches.value(39), because switches are always either true (on) or false (off).

[Edit: added ! so it shows when the switch is off.]
I think he wanted show to be false when the switch is on? so show = !$gameSwitches.value(39)?
😴 Oops. I'll edit my post, thanks for mentioning that!
Hey! Thanks so much @caethyril & @AphoticAmaranth
Caethyril has come to my rescue for the second time :LZSlol:
It works as intended now!

One thing that I figured would happen is that the switch's state is persistent when the player returns to the title menu, which unfortunately creates inconsistent behavior with what a player might expect.
So, here's what I am hoping to achieve (this is to account for edge cases):
The player sets options, then plays the game and can no longer set specific options (that's what we just solved in this thread so far), then the player (in the same play session) decides to return to the title menu. The options should be visible from the title menu again.

So basically, I guess I am looking for any sort of method to "detect" when the player is in the game, and when the player is just on the title menu.
(I'm aware that switches reset whenever the game is exited, that's why I specified "in the same play session")

Maybe if there is a plugin or script that set switches when the player exits to the title menu?
Or I was trying to think if there is some sort of logical way of using <global meta> switches to detect these things - though nothing really comes to mind :LZSskeptic:
Olivia_MetaControls is my favorite persistent switches.
the only downside is that a variable or switch changes, it is automatically
saved instantly (in your case it might work).

I change it a bit so it only saves when teh game is actually saved 🙂
which I needed for my plugin.
Well, it was AphoticAmaranth who provided the original solution (and corrected mine)...I just wrote it a different way.

As you've noted, switches are only designed to be referenced within the game. They get initialised on boot and new game.

To decide if the player is "in-game" or not, you could try checking the scene stack, e.g.

SceneManager._stack.indexOf(Scene_Title) >= 0
This should be true iff the player accessed the options from the title screen. I guess you could use that as a "Show" condition?

If you want to synchronise the switch value across all saves, there's also:
I guess you could use that as a "Show" condition?
Oh wow, yeah, that works way better than whatever it was I was trying to do with switches :LZSlol:

But, that said, I don't want you to think that switch information was useless either, I actually still needed that information on integrating switches into the show option as I planned on having an option become available once the player has reached a certain point in the game.

Anyways, I would say that takes care of this! I'll mark this thread to be closed after a little bit more play testing.

Edit:
Yes! It seems to work perfectly. I did have to return to my old script I had started this thread with (except, of course changing the brackets [] to parentheses ()). Since my game has a lot of extra options for customizing the game to the player's liking, at the start of a new game the game asks players if they would like to adjust the settings (since we all know not everyone was raised on a healthy diet of PC gaming and Totalbiscuit), and so JUST checking whether the player was in the title scene or not meant that at the start of the game when it asks players to adjust the options, all of the options that I want the players to be able to adjust are not present. So I just used a game switch at the start: When the game starts, a switch is turned on, this allows those options to be seen. After the player closes the options menu, the switch is turned off and therefore those options can no longer be accessed for the remainder of the game.
Here's the code for future reference:
Code:
if ($gameSwitches.value(18) === true) {
show = true
} else {
show = SceneManager._stack.indexOf(Scene_Title) >= 0;
}
Tested a working. Feels great to have a well polished options menu :LZSproud:
Thank you once again @caethyril & @AphoticAmaranth

Marking this thread to be closed.
Ah, another possibility might've been to use a check like this instead:

SceneManager._stack.indexOf(Scene_Map) >= 0
I.e. "is the map in the scene stack", which should be true iff they're in-game (the opposite of "is the title in the stack"). If you have it working now, though, then no worries. Happy RPG Making! 😂

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/solved-yep-options-core-how-to-make-show-hide-code-work.151270/