MZ Cannot read property 'match' of undefined

It was working before and it started to not work out of nowhere. I'm on RPG Maker MZ and I'm using Visustella's plugins.
In my game, I want some actors to be able to transform and I managed to find a script on the web that did exactly that.
By transform, I mean that I want an actor to change its physical appearance and gain some stats out of it but I want it to only stay during a fight. Once the battle ends, I want the transformation to cancel itself.

The stat part is working.

The appearance part WAS working before, but now it's giving me the error message "Cannot read property 'match' of undefined".
I checked in the console and I saw that the game was unable to load a file and that's what caused the crash. Again, it was working before and I didn't add any other plugins in between.

I did a lot of testing and I found this:
The error message only appears when the battle ends and the actor needs to go back to his original look.
The error message only appears when the transformation is used by any actor that is not the party leader.
It's not caused by one actor, I have 3 actors that can transform and all 3 of them works by themselves but makes the game crash when put in the 2nd, 3rd or 4th slot in the party.

Here's the code that I said I found on the web and it was working before yesterday:

<JS On Add State>
if (user.isActor()) {
user._prevCharName = user._characterName;
user._prevCharIndex = user._characterIndex;
user._prevFaceName = user._faceName;
user._prevFaceIndex = user._faceIndex;
user._prevBattlerName = user._battlerName;
if (user.actorId() === 1) {
var charName = 'Character Transformation name';
var charIndex = 0;
var faceName = 'Face Transformation name';
var faceIndex = 0;
var battlerName = 'Battler Transformation name';
}
if (user.actorId() === 2) {
var charName = '2nd Character Transformation name';
var charIndex = 0;
var faceName = '2nd Face Transformation name';
var faceIndex = 0;
var battlerName = '2nd Battler Transformation name';
}
user.setCharacterImage(charName, charIndex);
user.setFaceImage(faceName, faceIndex);
user.setBattlerImage(battlerName);
user.refresh();
}
</JS On Add State>

<JS On Erase State>
var charName = user._prevCharName;
var charIndex = user._prevCharIndex;
var faceName = user._prevFaceName;
var faceIndex = user._prevFaceIndex;
var battlerName = user._prevBattlerName;
user.setCharacterImage(charName, charIndex);
user.setFaceImage(faceName, faceIndex);
user.setBattlerImage(battlerName);
user._priorityCharacterName = undefined;
user._priorityCharacterIndex = undefined;
user._prevFaceName = undefined;
user._prevFaceIndex = undefined;
user._priorityFaceName = undefined;
user._priorityFaceIndex = undefined;
user._prevFaceName = undefined;
user._prevFaceIndex = undefined;
user._priorityBattlerName = undefined;
user._prevBattlerName = undefined;
user.refresh();
</JS On Erase State>

So yeah, I just want this to work so you can change the script entirely if that's what needs to happen to fix it.
\The appearance part WAS working before, but now it's giving me the error message "Cannot read property 'match' of undefined".
I checked in the console and I saw that the game was unable to load a file and that's what caused the crash.
That's not going to be quite right - the error is going to come from a line of code trying to work with a variable that doesn't exist. You wouldn't get that error from just trying to load a file.

You might have a variable set to the result of a file that didn't load, but that's not quite the same thing, and then which file becomes of primary importance. You should post a screenshot of your error trace in the Console tab to get better help.

Here's the code that I said I found on the web and it was working before yesterday:
So this is mostly Yanfly's Transformation Tip & Trick. As a tip, whenever you post code you should use the CODE tags (the </> on the editing bar) to make sure the formatting and all special characters are preserved.

if (user.actorId() === 1) {
var charName = 'Character Transformation name';
var charIndex = 0;
var faceName = 'Face Transformation name';
var faceIndex = 0;
var battlerName = 'Battler Transformation name';
}
Is this actually what you have in your project? You could be getting errors from having filenames with spaces in them. If not, it's best not to change your posted code from what you're actually using, because you could be changing what's causing the problem 😉

Aside from that, there's nothing wrong in the code you posted. You need to show us the console error to try to narrow down what the actual problem is.
That's not going to be quite right - the error is going to come from a line of code trying to work with a variable that doesn't exist. You wouldn't get that error from just trying to load a file.

You might have a variable set to the result of a file that didn't load, but that's not quite the same thing, and then which file becomes of primary importance. You should post a screenshot of your error trace in the Console tab to get better help.


So this is mostly Yanfly's Transformation Tip & Trick. As a tip, whenever you post code you should use the CODE tags (the </> on the editing bar) to make sure the formatting and all special characters are preserved.


Is this actually what you have in your project? You could be getting errors from having filenames with spaces in them. If not, it's best not to change your posted code from what you're actually using, because you could be changing what's causing the problem 😉

Aside from that, there's nothing wrong in the code you posted. You need to show us the console error to try to narrow down what the actual problem is.

There, I fully launched my game (so this is not from a battle test) and tried to run away from a fight after my second party member transformed and this is what happens in the console:

1670020178128.png


And here's what the X is saying when I hover my mouse above it:
1670020313299.png


Also, the names "Character Transformation name" in the code aren't the real names. The real ones have the _ symbol where I needed to have a space.
So, unfortunately, all those VisuStella plugins make it hard to troubleshoot with their obfuscated code. See the <<computed>> instead of what the names of the functions are?

It looks like the last bit is coming from a check about having an SV Actor - if you turn off all of your plugins, do you still have the problem? What does the error say then?

Actually clicking over to the Console tab, instead of staying in Sources, might give a longer trace.
So, unfortunately, all those VisuStella plugins make it hard to troubleshoot with their obfuscated code. See the <<computed>> instead of what the names of the functions are?

It looks like the last bit is coming from a check about having an SV Actor - if you turn off all of your plugins, do you still have the problem? What does the error say then?

Actually clicking over to the Console tab, instead of staying in Sources, might give a longer trace.

First of all, here's the console tab you wanted me to click on:
1670021797353.png

Second, I tried to use the skill without any plugins and the appearance didn't change (obviously since there's no plugin anymore) but the game didn't crash when I ran away from the fight.

If you wanted me to take a screenshot of the console without the plugins, I'm afraid I don't know how to open the console without the plugins.
No, that's all good. So if you turn back on just the Skills and States, to make the transformation function, but leave the Battle Core off, what happens?

To open the console at any time, just press F8.
"Cannot read property 'match' of undefined".
I checked in the console and I saw that the game was unable to load a file and that's what caused the crash
my JS is very rusty, but, isn't 'match' a method? equivalent to Ruby's 'collect' or 'select'?
if there's a load error, it might be that the code is expecting a certain something to be an array or a hash, to which it expects to run the match() method over, but it's not loaded, hence 'undefined'

knowing that, and the faulty part being from Game_Actor, and the VS line number, and the fact that it's a load error (so, it shouldn't happen in a new game) hopefully you can narrow the search.
No, that's all good. So if you turn back on just the Skills and States, to make the transformation function, but leave the Battle Core off, what happens?

To open the console at any time, just press F8.
Sorry for the late reply, I didn't touch rpg maker all weekend. As for the testing, I tried to run the game with only the Skills and states plugin and the transformation worked again, I opened the console and it still showed me an error message tho;
1670269457693.png

my JS is very rusty, but, isn't 'match' a method? equivalent to Ruby's 'collect' or 'select'?
if there's a load error, it might be that the code is expecting a certain something to be an array or a hash, to which it expects to run the match() method over, but it's not loaded, hence 'undefined'

knowing that, and the faulty part being from Game_Actor, and the VS line number, and the fact that it's a load error (so, it shouldn't happen in a new game) hopefully you can narrow the search.
As for this comment, even tho I'm just a beginner in this, the comment actually made sense to me somehow. So I'll try to run some test with a new game.
EDIT: So I tried to run the game with the New game option and it still gave me the crash treatment. I tried to run the game WITH battlecore on for this test and it crashed so I guess it's my BattleCore that's doing this.
Sorry for the late reply, I didn't touch rpg maker all weekend. As for the testing, I tried to run the game with only the Skills and states plugin and the transformation worked again, I opened the console and it still showed me an error message tho
That is a part of all RPG Maker projects, it doesn't affect anything. The salient part is that the code works fine with just Skills and States.

I tried to run the game WITH battlecore on for this test and it crashed so I guess it's my BattleCore that's doing this.
Yes. And it appears to be coming from functions that are checking what kind of SV battler is assigned, but because the Battle Core has obfuscated code we can't look at that function to see what's going on.

Unless anyone else has ideas, I can only suggest you follow VisuStella's procedures to file a bug report.
That is a part of all RPG Maker projects, it doesn't affect anything. The salient part is that the code works fine with just Skills and States.


Yes. And it appears to be coming from functions that are checking what kind of SV battler is assigned, but because the Battle Core has obfuscated code we can't look at that function to see what's going on.

Unless anyone else has ideas, I can only suggest you follow VisuStella's procedures to file a bug report.
So I just got back from talking with VisuStella's team and they don't know what the issue is either so I guess I'm gonna try to find what the issue is.
my JS is very rusty, but, isn't 'match' a method? equivalent to Ruby's 'collect' or 'select'?
if there's a load error, it might be that the code is expecting a certain something to be an array or a hash, to which it expects to run the match() method over, but it's not loaded, hence 'undefined'

knowing that, and the faulty part being from Game_Actor, and the VS line number, and the fact that it's a load error (so, it shouldn't happen in a new game) hopefully you can narrow the search.
With what you remember from JS, do you think you could write or at least tell me what you would've wrote instead? If you do remember that is haha.
hard to tell without knowing the structure we're working with.
I'm not familiar with VS plugins, and if that line number is correct, it's 17 THOUSAND lines of code intentionally written to make it hard to read.
can you go to the code and copy the block containing line 17819?
hard to tell without knowing the structure we're working with.
I'm not familiar with VS plugins, and if that line number is correct, it's 17 THOUSAND lines of code intentionally written to make it hard to read.
can you go to the code and copy the block containing line 17819?
So I checked the code of the battlecore and there's nothing at line 17819.
However the error message mentioned line 18281 so I put it here in case that's what you meant.
So I checked the code of the battlecore and there's nothing at line 17819.
However the error message mentioned line 18281 so I put it here in case that's what you meant.
You're off on the wrong track - the entire side discussion about "loading" is from you saying in your first post "I saw that the game was unable to load a file and that's what caused the crash" - which is, in fact, not related to the crash. That's a generic error that every MV and MZ project has.

The "property 'match' of undefined" means at some point in the code it is trying to use something (probably a spritesheet) that doesn't exist.

Where do you see anything about 18281?

Regardless, it's basically impossible for anyone here to help troubleshoot the individual, obfuscated lines of code. If VisuStella tested your project and can't find the cause, I don't know what recourse you have.
You're off on the wrong track - the entire side discussion about "loading" is from you saying in your first post "I saw that the game was unable to load a file and that's what caused the crash" - which is, in fact, not related to the crash. That's a generic error that every MV and MZ project has.

The "property 'match' of undefined" means at some point in the code it is trying to use something (probably a spritesheet) that doesn't exist.

Where do you see anything about 18281?

Regardless, it's basically impossible for anyone here to help troubleshoot the individual, obfuscated lines of code. If VisuStella tested your project and can't find the cause, I don't know what recourse you have.
I'm just trying to work around the issue since Visustella tested the thing and it apparently worked on their side by just changing what the actor changes into.

Then they sent me the "now working" java code but it didn't work from my side just like the first one so I'm trying to find something else that will work.

I'm really out of options.
Well, why don't you show us that? We might be able to see something wrong - if it works for them, it ought to work for you.

(side note: Java is not the same as JavaScript)
So I checked the code of the battlecore and there's nothing at line 17819.
However the error message mentioned line 18281 so I put it here in case that's what you meant.
that doesn't do either, because it's not structured as needed.
like I said, I'm not familiar with VS, but the game IS reading it as it would be structured, so using the game's own report it should be possible to find (or at least narrow down) the problem.
what I need is a proper plugin... the zero of reference from where to count lines.

try this:
backup the original visu_mz_1 and replace it with the attached file.
it's the same file, but cut into separate lines.
it SHOULD throw a different line number each time.
I managed to narrow the call to one of 64, 43 or 10 lines out of that mess, depending on how you search for it.

The "property 'match' of undefined" means at some point in the code it is trying to use something (probably a spritesheet) that doesn't exist.

Where do you see anything about 18281?
from what I've seen, it might be something like
Code:
if this.hasproperty?{return  .... };

where

object.prototype.hasproperty? = function{
variable.match('regexp')
}

where regexp = </SIDEVIEW ...>

which ties to Game_Actor.().() [as hasSvBattler]
would be logical to tie "Has?" to "this regexp exists?" to "ok, bring the code from there" and that code leading to a dead end.
that doesn't do either, because it's not structured as needed.
like I said, I'm not familiar with VS, but the game IS reading it as it would be structured, so using the game's own report it should be possible to find (or at least narrow down) the problem.
what I need is a proper plugin... the zero of reference from where to count lines.

try this:
backup the original visu_mz_1 and replace it with the attached file.
it's the same file, but cut into separate lines.
it SHOULD throw a different line number each time.
I managed to narrow the call to one of 64, 43 or 10 lines out of that mess, depending on how you search for it.
You don't actually have to do that. In the console, there's a "{}" button you can click to pretty print the file, which will split it into formatted lines as usual and you can set breakpoints from there.
which will split it into formatted lines as usual and you can set breakpoints from there.
would that work even if the whole thing is written in one single line?
do we look at the character pointer from the beginning?
Well, why don't you show us that? We might be able to see something wrong - if it works for them, it ought to work for you.

(side note: Java is not the same as JavaScript)
Alright, for starters, here are the plugins I sent to VisuStella in the new project I created for them:
1670984501142.png

Now here's the State that the skill is supposed to apply to the battler:
1670984587258.png

The code isn't shown in the picture so I'll put it here:

<JS On Add State> if (user.isActor()) { user._prevCharName = user._characterName; user._prevCharIndex = user._characterIndex; user._prevFaceName = user._faceName; user._prevFaceIndex = user._faceIndex; user._prevBattlerName = user._battlerName; if (user.actorId() === 1) { var charName = 'Actor1'; var charIndex = 0; var faceName = 'Actor1'; var faceIndex = 0; var battlerName = 'Actor1_1'; } if (user.actorId() === 2) { var charName = 'Actor1'; var charIndex = 0; var faceName = 'Actor1'; var faceIndex = 0; var battlerName = 'Actor1_2'; } user.setCharacterImage(charName, charIndex); user.setFaceImage(faceName, faceIndex); user.setBattlerImage(battlerName); user.refresh(); } </JS On Add State> <JS On Erase State> var charName = user._prevCharName; var charIndex = user._prevCharIndex; var faceName = user._prevFaceName; var faceIndex = user._prevFaceIndex; var battlerName = user._prevBattlerName; user.setCharacterImage(charName, charIndex); user.setFaceImage(faceName, faceIndex); user.setBattlerImage(battlerName); user._priorityCharacterName = undefined; user._priorityCharacterIndex = undefined; user._prevFaceName = undefined; user._prevFaceIndex = undefined; user._priorityFaceName = undefined; user._priorityFaceIndex = undefined; user._prevFaceName = undefined; user._prevFaceIndex = undefined; user._priorityBattlerName = undefined; user._prevBattlerName = undefined; user.refresh(); </JS On Erase State>

They tried the code and it worked for them and they say they didn't change anything except the "Actor1", "Actor1_1" and "Actor1_2" parts.
-------------
So I tried to replace the names with Actor1 and etc. since they said that's how they made it work.
Here's what it looks like from my side:
1670985099317.png

1670985053703.png

And of course here's the code I have on my side:
<JS On Add State> if (user.isActor()) { user._prevCharName = user._characterName; user._prevCharIndex = user._characterIndex; user._prevFaceName = user._faceName; user._prevFaceIndex = user._faceIndex; user._prevBattlerName = user._battlerName; if (user.actorId() === 1) { var charName = 'Actor1'; var charIndex = 0; var faceName = 'Actor1'; var faceIndex = 0; var battlerName = 'Actor1_1'; } if (user.actorId() === 2) { var charName = 'Actor1'; var charIndex = 0; var faceName = 'Actor1'; var faceIndex = 0; var battlerName = 'Actor1_2'; } user.setCharacterImage(charName, charIndex); user.setFaceImage(faceName, faceIndex); user.setBattlerImage(battlerName); user.refresh(); } </JS On Add State> <JS On Erase State> var charName = user._prevCharName; var charIndex = user._prevCharIndex; var faceName = user._prevFaceName; var faceIndex = user._prevFaceIndex; var battlerName = user._prevBattlerName; user.setCharacterImage(charName, charIndex); user.setFaceImage(faceName, faceIndex); user.setBattlerImage(battlerName); user._priorityCharacterName = undefined; user._priorityCharacterIndex = undefined; user._prevFaceName = undefined; user._prevFaceIndex = undefined; user._priorityFaceName = undefined; user._priorityFaceIndex = undefined; user._prevFaceName = undefined; user._prevFaceIndex = undefined; user._priorityBattlerName = undefined; user._prevBattlerName = undefined; user.refresh(); </JS On Erase State>

Like I said, I changed the same things they did in the code just to make sure. Once I use the skill, just like in VisuStella's gif, the 2 battler transforms. But then, when I try to flee, the error message appears.
------------
After my discussion with them, they told me the exact same thing you did 2 weeks ago; try to rename your files so there aren't any spaces and weird symbols.

So I spent 10 minutes removing spaces and symbols everywhere in my game files and then I did the same inside the game since it wouldn't detect anything anymore since the names were now different.

Then I took 5 minutes to change the filenames and the codes for the characters involved in the playtest and the same error message appeared from my side.
-----------
Is there any other information you need?

P.S- I tried to put VisuStella's gif in the message but the website said the file was too big so rip.

Original thread: https://forums.rpgmakerweb.com/threads/cannot-read-property-match-of-undefined.153072/