Escape -> crash after particular skill used

I have a character who has a transform skill. If it is not used, everything is fine. However, once it's used, if the player tries to escape, the game crashes, with one exception. That exception is if it is this particular character who uses Escape. The console shows this:

error message.png


I looked at the line in rmmz_managers, but couldn't see what that had to do with 'match' as that term is not used in that particular little section.

Neither can I understand why the message is refering to Static SV Battler. I don't have any static battlers, they are all animated.

I wondered if there was something in the state which effects the transformation, but couldn't see anything off about it. Also, the transformed actor can use escape without difficulty. However, for the sake of completeness, here is the note tag I have for that state in case there's something I've overlooked.

Code:
<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;
    const charName = "Actor1";
    const charIndex = 4;
    const faceName = "Actor_Emos_01";
    const faceIndex = 4;
    const battlerName = "Garen_transformed";
    user.setCharacterImage(charName, charIndex);
    user.setFaceImage(faceName, faceIndex);
    user.setBattlerImage(battlerName);
    user.refresh();
  }
</JS On Add State>

<JS On Erase State>
  const charName = user._prevCharName;
  const charIndex = user._prevCharIndex;
  const faceName = user._prevFaceName;
  const faceIndex = user._prevFaceIndex;
  const battlerName = user._prevBattlerName;
  user.setCharacterImage(charName, charIndex);
  user.setFaceImage(faceName, faceIndex);
  user.setBattlerImage(battlerName);
  delete user._prevCharacterName;
  delete user._prevCharacterIndex;
  delete user._prevFaceName;
  delete user._prevFaceIndex;
  delete user._prevBattlerName;
  user.refresh();
</JS On Erase State>

And finally, in case there is something basic that I've got wrong, here is the state

state.png


Sorting this out is way above my pay grade, so any help would be greatly appreciated.

Thank you.
I looked at the line in rmmz_managers, but couldn't see what that had to do with 'match' as that term is not used in that particular little section.
Your error isn't saying that it is.

Error traces go from the top down - it's saying there's a property "match" that's undefined as called by line 19,457 of the VisuStella Battle Core. And I think you know the issues with trying to troubleshoot those.
Neither can I understand why the message is refering to Static SV Battler. I don't have any static battlers, they are all animated.
It's referred to by a function called hasStaticSvBattler - emphasis mine. That would reasonably be code that checks whether or not a battler has a static SV battler or not.

here is the note tag I have for that state
That looks like a bastardization of Yanfly's Transformation Tip & Trick. I've seen others try to adapt it to VisuStella and run into lots of problems - in fact, this person had the exact same error as you:
@ATT_Turan That thread made for depressing reading, although the OP seemed to have a lot of additional problems because of giving the skill to more than one actor.

I'm not sure what I can do here, as the fact that this character has this ability is integral to the story, not some optional add-on. I dread the thought of having to rewrite the whole thing.

Anyway, thanks for the info.
Sorry, I'm not sure what else to say. As you saw, that person ended up resorting to doing it via events. Apparently even VisuStella support couldn't get it reliably functioning for him - I have no clue why.
If you want to upload your project (or a new project that replicates the issue) somewhere, and PM me a link, I can try to take a look at this for you.
@Kes
You can try to bughunt from the other direction - which unfortunately has no guarantee of success either.

"of undefined" always means that the engine was given a reference that does not exist.

Given the descriptions it is likely that the missing reference was on the battler before the transformation, but the info was lost during transformation - which is why the transformed actor causes the crash when that info is accessed by the engine. And if he escaped he isn't processed the same way...

This is actually extremely common with all types of summons and transformations during battle when a modified battleengine adds the data only at battle setup.
And it is also the reason why all suggestions always go to use only summon plugins wrtitten for that specxific engine, because only in that case the summon plugin knows what data has to be added for that engine to not crash.

And from all other info, the old yanfly transform/summon is not compatible to Visustella, which means you'll have to look for a Visustella Summon Plugin to use.

And that is where I have to stop - I have absoilutely no idea what options exist for Visustella.
@ATT_Turan I have done it with events, though it is not (at the moment, anyway) quite as smooth. At least, though, I can be more relaxed about it instead of wandering around in a state of anxiety about having the redo my project. That may enable clearer thinking.

@Andar Having checked there is no VisuStella summons plugin. I may have to go hunting some other plugin and see if it is compatible. I suspect that may be a tough condition to meet.

@Arthran Thank you for your kind offer. I'll put something together and send you a pm with the link.

Thanks to everyone for your help and advice on this.
Alright, folks, I got to the bottom of this like it was a case of Mallomars. I'm going to go ahead and post the solution here, in case anyone else ever has this problem and manages to come across this post in a search:

The code in the state note tag is using the user object to refer to the transformed character. However, user refers to the currently active battler (at the time the code in the note tag is executed).

When the battle ends, the state gets removed, which triggers the JS On Erase State code. As Kes mentioned, the crash happens when any actor *other* than the transformed actor initiates the escape. That's because the state is getting removed when another actor is the currently active battler, which means that (at that moment) user refers to that other actor, instead of the transformed one. This results in the code setting all of that other actor's image data to undefined, which is triggering the error.

To fix it, simply replace all occurrences of "user" with "target", in the JS On Erase State note tag. Personally, I would also recommend doing so in the JS On Add State note tag as well, though it's not strictly necessary in this case.

In Kes's particular situation, replacing the previous note tags with this should do the trick:
Spoiler: Code
Code:
<JS On Add State>
  if (target.isActor()) {
    target._prevCharName ??= target._characterName;
    target._prevCharIndex ??= target._characterIndex;
    target._prevFaceName ??= target._faceName;
    target._prevFaceIndex ??= target._faceIndex;
    target._prevBattlerName ??= target._battlerName;
    const charName = "Actor1";
    const charIndex = 4;
    const faceName = "Actor_Emos_01";
    const faceIndex = 4;
    const battlerName = "Garen_transformed";
    target.setCharacterImage(charName, charIndex);
    target.setFaceImage(faceName, faceIndex);
    target.setBattlerImage(battlerName);
    target.refresh();
  }
</JS On Add State>

<JS On Erase State>
  const charName = target._prevCharName;
  const charIndex = target._prevCharIndex;
  const faceName = target._prevFaceName;
  const faceIndex = target._prevFaceIndex;
  const battlerName = target._prevBattlerName;
  target.setCharacterImage(charName, charIndex);
  target.setFaceImage(faceName, faceIndex);
  target.setBattlerImage(battlerName);
  delete target._prevCharacterName;
  delete target._prevCharacterIndex;
  delete target._prevFaceName;
  delete target._prevFaceIndex;
  delete target._prevBattlerName;
  target.refresh();
</JS On Erase State>
As someone who has access to this project (bug testing/fixing) I just inserted the new note and it works flawlessly!
I was bug tracking it down slowly and (might) have gotten to it eventually, as I was looking at everything slowly to make sure I wasn't missing anything... but I have no idea how long it would have been before I swapped 'user' for 'target' in the state note.

@Kes is going to be so pleased with this, and I can stop making my headache worse trying to figure this issue out.
Thank you for that @Arthran! 😀
@Arthran I thought I'd take a quick look here before going out to work, and I'm so glad I did. A huge thank you for this - and for giving a clear explanation of the cause. Getting this fix is a big relief for me. I'm sure it will be a help to others too.
This thread is being closed due to being solved. If you need it reopened, report it to let us know why. Thank you!

Original thread: https://forums.rpgmakerweb.com/threads/escape-crash-after-particular-skill-used.158562/