Chech if save file has a certain switch ON?

In my project I only use one save file, so that should make it slightly easier.

Basically, I have the Game Credits scene accessible from title screen... although the credits are more-or-less a cinematic cutscene. And I want to make the cutscene different depending on the player's progress.

If the player is in early game, or hasn't even started, credits are pretty plain and simple.

If the player is past certain point (Switch XY == ON), credits sequence would look slightly different, containing some stuff that might be spoilerish for early game.

If the player finished the game (so credits are played at the end), they would go full-on different, hinting and pointing at some plot points etc.


So basically, I need a code snippet that, upon calling, will open save file1, check if switch X is true, and if it is - if switch y is true as well. Preferably save the result into a variable - 0 for both switches off, 1 for switch X, 2 for switches X and Y.
Without knowing what your code is for the credits, here would be some pseudo code.

In the game, you can set the variable to 1 when you flip switch X and 2 when you flip switch Y.
Code:
Scene_Credits.prototype.start = function() {
    this.displayCredits(this.checkPlayerProgress());
};

Scene_Credits.prototype.checkPlayerProgress = function() {
    var json = StorageManager.load(1);
    if (json) {
        DataManager.extractSaveContents(JsonEx.parse(json));
        return $gameVariables.value(1);
    }
    return 0;
};

Scene_Credits.prototype.displayCredits = function(progress) {
    switch (progress) {
    case 0:
        this.playBasicCredits();
        break;
    case 1:
        this.playIntermediateCredits();
        break;
    case 2:
        this.playAdvancedCredits();
        break;
    }
};
Without knowing what your code is for the credits, here would be some pseudo code.

There is no code whatsoever for credits - they're done on a map, evented. I'm not too good with JS, so I'm sticking with eventing all I can 😀

Although now that you wrote it, changing the variable in game and just retrieving it seems more logical than checking the switches and changing variable value. I presume this:
Code:
Scene_Credits.prototype.checkPlayerProgress = function() {
   var json = StorageManager.load(1);
   if (json) {
       DataManager.extractSaveContents(JsonEx.parse(json));
       return $gameVariables.value(1);
   }
   return 0;
};

Checks the variable's value... How would I alter it, so I could put it in Event's Script command to change variable X to saved file's var X?

Thanks for the help!
Oh I understand, the credits is just a map, but you can get there from the title screen. I guess you're using some sort of plugin for that, but that's not important for this.

You can put this into the script command of an event:
Code:
var json = StorageManager.load(1);
if (json) {
    var saveData = JsonEx.parse(json);
    $gameVariables.setValue(5, saveData.variables.value(5));
}
Replace 5 with the Variable # you are using.

EDIT: Changed the code so it doesn't crash if there is no Save File
Just tested, and it works perfectly! Thanks!
@ekhartpl I just realized that the first code I gave you would crash the game if there is no Save File. For example, if a new player tries to access the credits it would crash.
I edited the post to fix that.

Original thread: https://forums.rpgmakerweb.com/threads/chech-if-save-file-has-a-certain-switch-on.92953/