How can I disable javascript plugin functions with if statement?

Sorry if I ask something quite obvious, but I am trying to achieve that the plugin "Galv Battle Action Info" would disable if game switch 5 is not TRUE. My problem is that I get error when I try to add

Code:
if ($gameSwitches.value(5) === true) {
    return true;
    }

I have not yet figured the way to make it that the script cancels when the switch is not true. 😅

BUT THE BIGGEST PROBLEM is that the game gives me error in the console and says "Cannot read property 'value' of null' and value meaning the one after $gameSwitches

Thank you so much for your help for my past requests and possibly even for this one! I am still very early in learning javascript, and any help you might give would be appreciated for millenniums! 😊
That's because the game loads the plugin before even loading the game itself. $gameSwitches isn't yet defined at that stage, hence why you get an error that tells you that $gameSwitches is not null (I suspect that you inserted that bit of code a bit after, since it should give you undefined if you placed it at the right place, which would still not work). Take a look at the main.js code:

Code:
PluginManager.setup($plugins);

window.onload = function() {
    SceneManager.run(Scene_Boot);
};

As you can see, the process loads the plugins into memory before even booting the game.
Sorry if I ask something quite obvious, but I am trying to achieve that the plugin "Galv Battle Action Info" would disable if game switch 5 is not TRUE.
Yes indeed as @MushroomCake28 mentioned above it's not a simple as that since plugin script is executed before the actual game is setup (that of course means no global objects such as $gameSwitches can be used directly like that)... instead the proper way is to alias or mod certain key functions within the script...
...honestly the best (easiest) options for you it seems are to make a mod of the script... change the "update" function of "Window_BattleAttackInfo" to something like...
GALV_BattleActionInfo.js (line 537) said:
Spoiler
Code:
Window_BattleAttackInfo.prototype.update = function() {
    this.visible = $gameSwitches.value(5); // <== Added this line (only visible if switch 5 is true)
    if (this._enemyWindow.active) {
        this.updateMotion();
        if (this._currentIndex !== this._enemyWindow._index || this._currentItem !== this.action()._item || this._currentWindow !== this._enemyWindow) {
            this._currentWindow = this._enemyWindow;
            this.refresh();
        };
    } else if (this._actorWindow.active) {
        this.updateMotion();
        if (this._currentIndex !== this._actorWindow._index || this._currentItem !== this.action()._item || this._currentWindow !== this._actorWindow) {
            this._currentWindow = this._actorWindow;
            this.refresh();
        };
    } else {
        if (this._momentum > 0) this._momentum = 0;
        this._momentum = this._momentum - 5;
        this.y = Math.max(this.y + this._momentum,-this._height + this._peekHeight);
        this._currentIndex = -1;
        this._currentItem = null;
    };
};
...or if already in the battle scene... simply you could use the following script call to adjust visibility 😉
Spoiler
Code:
if (SceneManager._scene._attackInfoWindow) SceneManager._scene._attackInfoWindow.visible = !SceneManager._scene._attackInfoWindow.visible;
1582073983201.png
and there is another problem that has nothing to do with your error.

you can't simply disable an entire plugin during runtime. That is the same as if you want to exchange the motor of your car while driving on the highway.
Even adding or removing a plugin while the game is stopped usually causes savefiles to become incompatible due to the fact that this can change what is stored in and loaded from the savefiles. There is a reason why we always say to start a new game after changes to the plugin manager....

What you can do is to disable partial functions of a plugin. That requires you to go into the plugin and modify the specific functions of it to react to the switch - that would also circumvent the problem you originally had, because at that time when those functions are running the variables will already be defined.
You just have to make sure not to disable those functions of the plugin that changes savedata, or those that are for setting up the plugin. You can only disable the later runtime functions of it.

of course, identifying those functions requires much more programming knowledge than trying to place a switch around everything...
Got this cleared on my own. Made it not based on switches, but made a variable value inside the script itself and made it either 0 or 1. If the number is 1, the script function is show, otherwise not.
@eluukkanen If you're problem has been fully resolved, please don't forget to report your thread so it can be closed. Thank you.
You could have done it with switches. The difference between what you started with, and what you got to work, was not about switches vs variables, but about where you put the code. If you had put the variable check in the same place as the switch check, you would have received the same error.

Original thread: https://forums.rpgmakerweb.com/threads/how-can-i-disable-javascript-plugin-functions-with-if-statement.118348/