Frustrating Crash Glitch

Okay, so I'm making what I was hoping to be a quick boss fight game involving 4 heroes beating up an evil guy called the Godmodder. I hadn't installed/activated any plugins, and I had been making good progress until I tried making a metronome-like move using a Common Event and if/else conditional branches.

Then, during playtesting, it began to crash when I used the move. Here's a couple of copypastes of the console during a couple of times when this occurred:

rpg_managers.js:1949 TypeError: Cannot read property 'scope' of null
at Game_Action.checkItemScope (rpg_objects.js:1302)
at Game_Action.isForOpponent (rpg_objects.js:1306)
at Game_Action.makeTargets (rpg_objects.js:1447)
at Function.BattleManager.startAction (rpg_managers.js:2509)
at Function.BattleManager.processForcedAction (rpg_managers.js:2600)
at Function.BattleManager.updateEvent (rpg_managers.js:2271)
at Function.BattleManager.update (rpg_managers.js:2244)
at Scene_Battle.updateBattleProcess (rpg_scenes.js:2265)
at Scene_Battle.update (rpg_scenes.js:2257)
at Function.SceneManager.updateScene (rpg_managers.js:2024)
SceneManager.catchException @ rpg_managers.js:1949

PixiJS 4.5.4 - ✰ WebGL ✰ http://www.pixijs.com/ ♥♥♥


rpg_managers.js:1949 TypeError: Cannot read property 'scope' of null
at Game_Action.checkItemScope (rpg_objects.js:1302)
at Game_Action.isForOpponent (rpg_objects.js:1306)
at Game_Action.makeTargets (rpg_objects.js:1447)
at Function.BattleManager.startAction (rpg_managers.js:2509)
at Function.BattleManager.processForcedAction (rpg_managers.js:2600)
at Function.BattleManager.updateEvent (rpg_managers.js:2271)
at Function.BattleManager.update (rpg_managers.js:2244)
at Scene_Battle.updateBattleProcess (rpg_scenes.js:2265)
at Scene_Battle.update (rpg_scenes.js:2257)
at Function.SceneManager.updateScene (rpg_managers.js:2024)
SceneManager.catchException @ rpg_managers.js:1949

Hoping it was merely a glitch/minor corruption with how the Project Folders were initialized/created, I opened up a new project and just copy/pasted everything from the Database screens onto the new project. It still crashed.

How the skill itself goes is that it calls upon a common Event that just sets a variable to a random number between 1 and 15. Then it compares the numbers until it hits the conditional meant to deploy said move.

Only 2 moves aren't your standard attacks/buff/debuffs/buff or debuff nullifiers and both of them call upon common events to crate items that you can use mid-battle. All of the moves used in the metronome-like attack use TP exclusively. To be honest, I was testing this and everything seemed to work smoothly until I re-introduced the items that were meant to be created, but those items/the skills that create those items by themselves don't cause any problems.

Any help at all would be greatly appreciated. Thank you in advanced.
A screenshot of your common event would help.
A screenshot of your common event would help.
Alright. Since I did this the same way for all four of the main party members, I'll be sure to get screenshots for all of them. Might take more than one each though...

I'll put them in spoilers due to how large and how many there are.
Spoiler: Pictures Here
upload_2019-5-7_7-56-54.png
upload_2019-5-7_7-57-13.png

upload_2019-5-7_7-57-51.png
upload_2019-5-7_7-58-4.png
upload_2019-5-7_7-58-17.png
upload_2019-5-7_7-58-29.png
upload_2019-5-7_7-58-48.png
upload_2019-5-7_7-58-58.png
upload_2019-5-7_7-59-12.png
upload_2019-5-7_7-59-25.png
upload_2019-5-7_7-59-39.png
upload_2019-5-7_7-59-50.png
Those are the screenshots of my common event and its three permutations. If you need any more, just ask! I'll keep my game open so I can get them to you as soon as possible.
"scope" is a skill property and the error indicates that the skill the engine is trying to use either doesn't exist or can't find its target.
I can't go through all your screenshots and compare them with your database - that is something only you can do.
But somehow one of the force action settings point to a skill that has been deleted since or something around that.

If you can't find the wrong command with that, then you'll have to add show text into every branch of the common event telling you that it is about to be executed (after the conditional branch part but before the force action command.
That way you'll get a lot of messages during skill execution, and the last message you get before the error will be the one where you messed up the force action settings.
"scope" is a skill property and the error indicates that the skill the engine is trying to use either doesn't exist or can't find its target.
I can't go through all your screenshots and compare them with your database - that is something only you can do.
But somehow one of the force action settings point to a skill that has been deleted since or something around that.

If you can't find the wrong command with that, then you'll have to add show text into every branch of the common event telling you that it is about to be executed (after the conditional branch part but before the force action command.
That way you'll get a lot of messages during skill execution, and the last message you get before the error will be the one where you messed up the force action settings.
Thanks a million! It finally gave me the thing that was causing the crash! Which is really bizarre because it works just fine when I manually trigger it!

It was the revival spell! I am not entirely sure what is up with that. My entire party is not dead, though.

WAIT. DUH. THAT'S WHY.

The scope of the skill is to use it on a dead ally! But there are no dead allies! So the program has a brief meltdown! This is an easy of a fix as simply removing the revive spell from the list!

Thank you so very much! I should have done this from the getgo, but I forgot it was even a thing until you reminded me! Again, thank you!
No, I don't think that's why. The error message says "can't read property 'scope' of 'null'" which means the item or skill is null. Nothing at all about how many dead party members you have. It hasn't even got to the stage of looking for targets.

It seems to me like you've used a skill or an item in your common event, and have then deleted that skill or item from the database.
No, I don't think that's why. The error message says "can't read property 'scope' of 'null'" which means the item or skill is null. Nothing at all about how many dead party members you have. It hasn't even got to the stage of looking for targets.

It seems to me like you've used a skill or an item in your common event, and have then deleted that skill or item from the database.
But removing the revival skill from the list of attacks to be randomly chosen from worked. Neither I nor anyone else has complained or seen any crashes.

And I didn't delete any of the items or skills from the common events once I made them. At least not in a way that would cause it to have a null place.

I think the confusion lies in what 'scope' it's actually referring to. From what I can see, in each skill in MV there's a section literally labeled as Scope. One of the options is '1 Ally (Dead)'. I suspect that what happens is that when there's no dead allies in the list, what's there is effectively a 'null' value. I believe the game tries to apply the skill to something from the list/nonexistent list as it's run, and then crashes because it has to handle a null error.

However since 'Scope' can refer to a lot of things like lists of skills or items or common events, it's confusing to try and pin down.

While I'm thinking of it, I think I'll look back at that code and see if I can confirm this.

*snop*
Then, during playtesting, it began to crash when I used the move. Here's a couple of copypastes of the console during a couple of times when this occurred:

rpg_managers.js:1949 TypeError: Cannot read property 'scope' of null
at Game_Action.checkItemScope (rpg_objects.js:1302)
at Game_Action.isForOpponent (rpg_objects.js:1306)
at Game_Action.makeTargets (rpg_objects.js:1447)
at Function.BattleManager.startAction (rpg_managers.js:2509)
at Function.BattleManager.processForcedAction (rpg_managers.js:2600)
at Function.BattleManager.updateEvent (rpg_managers.js:2271)
at Function.BattleManager.update (rpg_managers.js:2244)
at Scene_Battle.updateBattleProcess (rpg_scenes.js:2265)
at Scene_Battle.update (rpg_scenes.js:2257)
at Function.SceneManager.updateScene (rpg_managers.js:2024)
SceneManager.catchException @ rpg_managers.js:1949

*snip*
Two of the things included in the errors is 'isForOpponent' and 'makeTargets', which supports this. The 'checkItemScope' is weird, but it could simply refer to an item in a list from what I understand. From there it's just the null error causing a cascade of errors. Which is naturally obvious in retrospect since I now know what to look for.

I think I could have still kept the revive skill if I altered it to target 1 Ally in general or had it check to see if there was a valid target first before firing the spell. So I need to keep that in mind for if I want work more with or do more complicated things with random move selection in the future.

Still, thank you for giving me a reason to go over this with a more critical eye. Having my ideas challenged is important, especially with ones that is very likely and valid. I'll have to keep it in mind if I run into this sort of error again so I can check for it
After some research, it seems it is due to a null skill (as expected), but the root cause is a missing check in forceAction regarding null targets. 😅

randomDeadMember will return null for the target if there are no dead members in the target unit. The action is then cleared if the target is falsy (e.g. null). forceAction will then attempt to apply a null skill, causing the error. 👋 Supporting code excerpts (v1.5.2) in spoiler below~
Spoiler
Code:
Game_Unit.prototype.randomDeadTarget = function() {
    var members = this.deadMembers();
    if (members.length === 0) {
        return null;
    }
    return members[Math.floor(Math.random() * members.length)];
};

Game_Action.prototype.decideRandomTarget = function() {
    var target;
    if (this.isForDeadFriend()) {
        target = this.friendsUnit().randomDeadTarget();
    } else if (this.isForFriend()) {
        target = this.friendsUnit().randomTarget();
    } else {
        target = this.opponentsUnit().randomTarget();
    }
    if (target) {
        this._targetIndex = target.index();
    } else {
        this.clear();
    }
};

Game_Battler.prototype.forceAction = function(skillId, targetIndex) {
    this.clearActions();
    var action = new Game_Action(this, true);
    action.setSkill(skillId);
    if (targetIndex === -2) {
        action.setTarget(this._lastTargetIndex);
    } else if (targetIndex === -1) {
        action.decideRandomTarget();
    } else {
        action.setTarget(targetIndex);
    }
    this._actions.push(action);
};
With that in mind, it should be sufficient to check if there are any dead party members beforehand. 🙂
After some research, it seems it is due to a null skill (as expected), but the root cause is a missing check in forceAction regarding null targets. 😅

randomDeadMember will return null for the target if there are no dead members in the target unit. The action is then cleared if the target is falsy (e.g. null). forceAction will then attempt to apply a null skill, causing the error. 👋 Supporting code excerpts (v1.5.2) in spoiler below~
Spoiler
Code:
Game_Unit.prototype.randomDeadTarget = function() {
    var members = this.deadMembers();
    if (members.length === 0) {
        return null;
    }
    return members[Math.floor(Math.random() * members.length)];
};

Game_Action.prototype.decideRandomTarget = function() {
    var target;
    if (this.isForDeadFriend()) {
        target = this.friendsUnit().randomDeadTarget();
    } else if (this.isForFriend()) {
        target = this.friendsUnit().randomTarget();
    } else {
        target = this.opponentsUnit().randomTarget();
    }
    if (target) {
        this._targetIndex = target.index();
    } else {
        this.clear();
    }
};

Game_Battler.prototype.forceAction = function(skillId, targetIndex) {
    this.clearActions();
    var action = new Game_Action(this, true);
    action.setSkill(skillId);
    if (targetIndex === -2) {
        action.setTarget(this._lastTargetIndex);
    } else if (targetIndex === -1) {
        action.decideRandomTarget();
    } else {
        action.setTarget(targetIndex);
    }
    this._actions.push(action);
};
With that in mind, it should be sufficient to check if there are any dead party members beforehand. 🙂
Thank you very much! I was wondering how it worked! I suspected just checking for dead party members beforehand was sufficient, but this is so much better than just confirmation!

Original thread: https://forums.rpgmakerweb.com/threads/frustrating-crash-glitch.108762/