How can I disable javascript plugin functions with if statement?

eluukkanen

Game Dev
Veteran
Joined
Feb 16, 2016
Messages
355
Reaction score
244
First Language
Finnish
Primarily Uses
N/A
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. :rswt

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! :kaoblush:
 

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
3,952
Reaction score
4,870
First Language
EN, FR
Primarily Uses
RMMZ
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.
 

ct_bolt

Creator
Veteran
Joined
May 3, 2012
Messages
979
Reaction score
578
First Language
Javascript
Primarily Uses
RMMZ
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:
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 ;)
Code:
if (SceneManager._scene._attackInfoWindow) SceneManager._scene._attackInfoWindow.visible = !SceneManager._scene._attackInfoWindow.visible;
1582073983201.png
 
Last edited:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
34,763
Reaction score
8,975
First Language
German
Primarily Uses
RMMV
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...
 

eluukkanen

Game Dev
Veteran
Joined
Feb 16, 2016
Messages
355
Reaction score
244
First Language
Finnish
Primarily Uses
N/A
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.
 

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
3,952
Reaction score
4,870
First Language
EN, FR
Primarily Uses
RMMZ
@eluukkanen If you're problem has been fully resolved, please don't forget to report your thread so it can be closed. Thank you.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
44,647
Reaction score
15,738
First Language
English
Primarily Uses
RMMV
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.
 

Latest Threads

Latest Posts

Latest Profile Posts

At work.
Co: "This bug drove me insane. I tried a lot of things to debug, it just stuck".
Me: "How did you debug it?"
Co: *shows a complicated debugging method using breakpoints and everything*
Me: "What about ... " *casually prints a stack trace in the try/catch exception
Co: "Wait, you can do that??"
Totally original and unique OC
Harold.png
So after completing the Mass Effect Trilogy the first time as a Vanguard, I decided to replay the trilogy as a Soldier. Thus far, I've just finished the Horizon mission in ME2, and I'm already exhausted from ME2's f**k-awful enemy design.
If you are in these ices, I will give all the fire...
Yeah, now Yes !!!! "boom boom "
"Fire the monsters, guards!!!"

index.php

Forum statistics

Threads
118,659
Messages
1,117,598
Members
155,758
Latest member
Aevea
Top