Hello! 🙂 I have this skill that sometimes work but sometimes it doesn't and gives a script error in the console log, so I would like to ask for some help with it.
I am using Visustella's Passive States as part of this process. All plugins are latest version and arranged as on the website.
Effect: Below is the code I wrote for the skill as a Common event Extra effect unrelated to the target the player selected.
It is supposed to Find enemies with the Passive State 4, and then find 1 Random enemy from that group that isn't already effected by State 12 and apply State 12 to them. If all Passive State 4 enemies are effected by State 12, nothing happens.
When it works, my console logs the arrays, so I know its working as intended.
But when it doesn't it shows me this error
I have a feeling that I made an error with the Passive State but I'm not exactly sure where I went wrong, so if someone could teach me if I have an error somewhere! Thank you.
I am using Visustella's Passive States as part of this process. All plugins are latest version and arranged as on the website.
Effect: Below is the code I wrote for the skill as a Common event Extra effect unrelated to the target the player selected.
It is supposed to Find enemies with the Passive State 4, and then find 1 Random enemy from that group that isn't already effected by State 12 and apply State 12 to them. If all Passive State 4 enemies are effected by State 12, nothing happens.
Code:
//Create Array of Enemies with Visustella Passive State 4
const TotalLength = $gameTroop.aliveMembers().length;
let CanHit = [];
for (let i = 0; i < TotalLength + 1; i++){
if ($gameTroop.members()[i].states().includes($dataStates[4])){
CanHit.push($gameTroop.members()[i].index());
};
};
console.log(CanHit);
//Create New Array of Enemies from CanHit that does not have State 12 applied
let TargetEnemyGroup = [];
for (let i = CanHit[0]; i < TotalLength + 1; i++){
if ($gameTroop.members()[i].isStateAffected(12) == false){
TargetEnemyGroup.push(i);
};
};
console.log(TargetEnemyGroup);
//Pick a Random Enemy from TargetEnemyGroup, that should be a target that has Passive State 4 and No State 12
//Add State 12 to the Random Enemy
if (TargetEnemyGroup.length > 0){
const randomNum = Math.randomInt(TargetEnemyGroup.length);
const EnemyIndex = TargetEnemyGroup[randomNum];
$gameTroop.members()[EnemyIndex].addState(12);
} else {
console.log('All the free space is taken');
};
When it works, my console logs the arrays, so I know its working as intended.
But when it doesn't it shows me this error
I have a feeling that I made an error with the Passive State but I'm not exactly sure where I went wrong, so if someone could teach me if I have an error somewhere! Thank you.