Error With Yanfly's Self Switch & Self Variable Plugin [SOLVED]

Heyla!

So, I'm using Yanfly's Self Switch & Self Variable Plugin, which can be found here: http://www.yanfly.moe/wiki/Self_Switches_&_Variables_(YEP)

I'm using it with the Chrono Engine, which can be found here: https://atelierrgss.wordpress.com/rmv-chrono-engine/

My project version is 1.5.0

All I've done so far is make the self switches and self variables in the switches and variables list. And to make sure I wasn't using anything the Chrono Engine was using, I just expanded the maximum number of switches and variables and used those new slots for the self switches and self variables. I haven't even actually used them in any of my events, yet. I just reserved the spots so that, when I do need them, they're there. When I load up the game, everything seems to work fine as I work through each area. Then I get to the boss fight. At first, everything seems fine as I'm fighting the boss. Then, when her HP gets to a certain point, I get the following:

1576780924288.png


All I can make of it is that something in either the Chrono Engine or the Yanfly script is trying to use a function called key[2], but it's not registering as a legitimate function because reasons. I'm hoping that someone more knowledgeable can help me troubleshoot the root of the problem so that, hopefully, a solution can be found so that these plugins will play with each other.

Thanks for any and all your help!
TheKeeper
Did you start a new game after both plugins were added, or did you resume a game you'd saved earlier?

If you turn off the Chrono Engine plugin, do you still get the error on that battle?

Where in the troop tab for that battle are you turning switches on or off? What are the names of those switches? Can you show a screenshot of your troop event page?

Do all of your switches and variables that are being used here have names in the database?

Note - self switches and variables work on map events, but not on troop events, because there is no map id associated with troop events.
Did you start a new game after both plugins were added, or did you resume a game you'd saved earlier?

If you turn off the Chrono Engine plugin, do you still get the error on that battle?

Where in the troop tab for that battle are you turning switches on or off? What are the names of those switches? Can you show a screenshot of your troop event page?

Do all of your switches and variables that are being used here have names in the database?

Note - self switches and variables work on map events, but not on troop events, because there is no map id associated with troop events.

I started a new game after installing Yanfly's plugin. If I turn of Yanfly's plugin, the boss fight goes off without a hitch. The Chrono Engine is an ABS combat system, so turning it off to test the battle wouldn't work. In relation to that, because it's an ABS combat system, I don't use the troop database--just the enemy database. In case it'll help, though, here's a screenshot of the enemy database:

1576788980109.png


All of the switches and variables being used have names in the database, as far as I can tell (I'm using the Chrono Engine demo project file as the basis for my game, as there is just so much to it that starting from a new file seems to cause issues, if I overlook bringing something over, and it's way to easy to overlook bringing something over).

I haven't actually used the self-switches/variables, yet. I just installed the plugin and reserved the spots in the switches and variables list, for when I do need them.

=====
EDIT 1
=====

So I opened up the file in Notepad++ and found the function--key[2]-that the error is referring to:

1576790277226.png


So this script makes a reference to a function called key[2], but this function is apparently not previously defined, is what I'm beginning to think. And my thought process is saying, "Well, then, that means I need to add in a line that defines this function, yes?" But I'm not sure. Thoughts? Anyone?
You can't look at just that line that's throwing the error, and you're misinterpreting what it's saying.

key[2] is not a method, and that's not what the error message says. The error message says key[2].match is not a method. This means it's expecting the self switch ID passed in to be a string, and it's not (or it's not there at all).

Looking at it in context, this function is being called by the Chrono Engine script via Game_CharacterBase.setDeadSelfSwitch. Apparently that function is trying to do something with self switches that is different to the way self switches normally work, and is not compatible with Yanfly's plugin.

So the truth is Yanfly's plugin is fine, and the Chrono Engine is fine, as long as they're not used together. When used together you get an error, and it is not the fault of one plugin or the other. You need a compatibility patch.
You can't look at just that line that's throwing the error, and you're misinterpreting what it's saying.

key[2] is not a method, and that's not what the error message says. The error message says key[2].match is not a method. This means it's expecting the self switch ID passed in to be a string, and it's not (or it's not there at all).

Looking at it in context, this function is being called by the Chrono Engine script via Game_CharacterBase.setDeadSelfSwitch. Apparently that function is trying to do something with self switches that is different to the way self switches normally work, and is not compatible with Yanfly's plugin.

So the truth is Yanfly's plugin is fine, and the Chrono Engine is fine, as long as they're not used together. When used together you get an error, and it is not the fault of one plugin or the other. You need a compatibility patch.

Ah! Okay! Thank you, very much for clearing that up! That's why I ask the experts. xD So, I need a compatibility patch, eh? Well. Now, to figure out where to start, with that.
Can you post the function from Chrono Engine that includes line 2721?

I may be able to look at this for you later today, or over the weekend. If someone else doesn't provide a solution sooner. (Or maybe do a search and see if someone has already written one - I'd be surprised if you're the only person using the two of them together).
Sure thing! Here it is:

1576793893633.png


I'll also do a search as you suggested. Like you said, maybe someone's already come up with a solution!

=====
EDIT 1
=====

I did find a similar thread here: https://forums.rpgmakerweb.com/inde...-plus-moghunters-chrono-compatibility.101940/

But I'm not really sure I understood the solution that was being posed, here. It seems to involve disabling the script at various points in the gameplay? I really don't understand it.
Ah yes, I ran into this problem long ago. Never did find a fix for the dead switch issue, but back then I did testing and found http://himeworks.com/2015/12/self-variables/ works with the Chrono Engine. So if a solution can't be found, you may want to give that a shot. Or of course there is QABS and Alpha ABS if you wish to replace the Chrono Engine.
Ah yes, I ran into this problem long ago. Never did find a fix for the dead switch issue, but back then I did testing and found http://himeworks.com/2015/12/self-variables/ works with the Chrono Engine. So if a solution can't be found, you may want to give that a shot. Or of course there is QABS and Alpha ABS if you wish to replace the Chrono Engine.

Ah! Thanks for the tip! If worse comes to worst, I'll use Hime's script. That said, I'm hoping there's a solution for this, as Yanfly's script makes using self-variables much more intuitive and user-friendly.
Please show how you have set up the dead selfswitch id on the enemy in this particular battle (screenshot is best)

Also, please add the following line to Yanfly's script, above line 348:
Code:
console.log(key);

and grab another screenshot of the console after making the error happen again.
As far as the enemy setup goes, here's page 1:

1576809753487.png


Here's page 2:

1576809774998.png


And here's page 3:

1576809806098.png


That's the weird thing about all this: I'm not using the enemy dead self switch function for this particular enemy, but I'm getting the error with this enemy, anyhow. I actually have other enemies that use the dead self switch, but I don't get the error with them. The only self switch that is actually being used by this enemy is the one for the sensor. So I'm left scratching my head at this.

Also, here's how I added in that line of code:

1576809982887.png


I hope I inserted it correctly?

I'm still trying to get the error. For some reason, it's not coming up, anymore. Be back with that screenshot, once I get that error.
No, it needs to be immediately above line 348, and you put it above 346. It'll never get run.

If you are using the demo project and haven't changed it, enemy 6 does have a dead self switch, and you are using the enemy dead self switch function. It's set up in the Enemy tab.
Oh, I see! That counts as an enemy dead self switch. I didn't think it counted because it used the regular switch, but I suppose that's what's causing the conflict? Because Yanfly's script uses the regular switches, too?

Also, I'll put the code directly above the line and run it, again. For some reason, though, I'm not getting the error, anymore, and I'm not sure why. The only thing that's changed is that i've added a script that let's me switch party members with a keypress. That shouldn't be doing anything, right?

=====
EDIT 1
=====

Is this the right way?

1576811123237.png


=====
EDIT 2
=====

Okay, since I changed the position of that line, I'm getting the error, again. However, I think I'm still putting it in the wrong position? When I tried to bring up the console, it wouldn't come up.

=====
EDIT 3
=====

Or is this the right way?

1576812329590.png


Sorry, I don't mean to be dense about placement.
The second one was right.

Change the plugin back to that and save, play the game and hit F8 to open the console before any battle starts. Then battle.

In the demo, enemy 6 was set up to use self switch 12.

I don't really see why it's giving an error, which is why I'd like to see what's in the console when it occurs. You're not changing the self switch via the plugin command, so the Chrono script is calling this method directly. I'd like to see what switch it's trying to update.

Edit - the other two locations may have actually resulted in the plugin not being able to be loaded, which would explain why the error didn't happen then. However, the console should have had an error message to say there was something wrong with the plugin code.
The console won't come up when I press any of the function keys.

=====
EDIT 1
=====

Aha! I traced the problem to that one script I had added, earlier! For some reason, it prevents me from bringing up the console, when it's turned on. So I turned off the script, for now.

=====
EDIT 2
=====

Here, we go:

1576814649451.png
Nice! And this is exactly along the lines of what I expected to see.

I looked at enemy 6 again, and it uses a switch id, not a self switch id. You did say that but I didn't pick up on the difference, so was thinking that was where it was set. So forget about that.

What's happening here is that deadSelfSwitchID is being set to [] - a null array. Then the function is saying "if it's something, set the self switch". A null/empty array is something. So the error is actually with the Chrono script, not taking into account that a null array isn't the same as a null value.

Here's what you need to do ...

Go to line 1129 where it has this:
Code:
this._ras.deadSelfSwitchID = [];

and change it to this:
Code:
this._ras.deadSelfSwitchID = null;


Then it should work.

After testing and verifying this, you can go back to the Yanfly script and remove that extra line I got you to add.

(edited to add a little more background/explanation)

It seems Mog catered for turning on multiple switches or variables when an enemy was defeated, and the initialisation of the self switches indicates he intended to do the same thing. But when reading through enemy notes, he does push switch and variable ids into the array for those, but for self switches, he replaces the empty array with the full string contained in the note. So if you have multiple of those, each subsequent one is going to replace the one that came before. And then when processing an enemy's defeat, it checks the length of the switch and variable arrays, but expects the self switch to be a null value or the name of the self switch (which is a text string). If you haven't set up a dead self switch note tag, it is neither - instead, it's an empty array. And so it's passing an empty array through to the self switch function. The default Game_SelfSwitches.setValue function just uses whatever key is passed in without checking the type, but to do a text comparison, Yanfly's needs it to be a string, and objects when it isn't.
Nice! And this is exactly along the lines of what I expected to see.

I looked at enemy 6 again, and it uses a switch id, not a self switch id. So forget about that.

What's happening here is that deadSelfSwitchID is being set to [] - a null array. Then the function is saying "if it's something, set the self switch". A null/empty array is something. So the error is actually with the Chrono script, not taking into account that a null array isn't the same as a null value.

Here's what you need to do ...

Go to line 1129 where it has this:
Code:
this._ras.deadSelfSwitchID = [];

and change it to this:
Code:
this._ras.deadSelfSwitchID = null;


Then it should work.

After testing and verifying this, you can go back to the Yanfly script and remove that extra line I got you to add.

Yay! Your fix did it! I'm not getting the error, any more! Thank you, so much!
Awesome! If all resolved, just report your post and let the mods know, and they'll close the thread.

@ImaginaryVillain I know you're not still looking, but I thought you might be interested in the cause & solution, too 🙂
@Shaz It's been a long time since I messed with the Chrono Engine (really I just made my own homebrew ABS instead). But the solution is interesting just the same, thanks for letting me know! :LZSexcite:
Thread closed

Original thread: https://forums.rpgmakerweb.com/threads/error-with-yanflys-self-switch-self-variable-plugin-solved.116427/