How can I disable javascript plugin functions with if statement?

eluukkanen

Composer
Veteran
Joined
Feb 16, 2016
Messages
334
Reaction score
224
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
2,617
Reaction score
3,790
First Language
English
Primarily Uses
RMMV
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
718
Reaction score
247
First Language
Javascript
Primarily Uses
RMMV
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
29,541
Reaction score
6,874
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

Composer
Veteran
Joined
Feb 16, 2016
Messages
334
Reaction score
224
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
2,617
Reaction score
3,790
First Language
English
Primarily Uses
RMMV
@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

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,823
Reaction score
12,233
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.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Making it a rule that I don't do any world building for my new game before the actual gameplay is concrete and working. I have 16 years of lore to work with anyway.
Cheesy power metal makes everything better. No matter what you do, you'll feel heroic doing it.
Starting to really like the first of my madness areas. I think the eyes looking at them really helps to sell the place. :LZSexcite:
Made idle animation for character. It first had only three frames but looked too different from walking animation and I had to draw five more.
MV and VX Ace both have good qualities.

Forum statistics

Threads
95,694
Messages
931,075
Members
126,032
Latest member
MadAtticGames
Top