Switching Status Effects With Target

I'm trying to create a skill that transfers a target's current status effects to the user and vice versa. It only seems to work when the enemy currently has no statuses. I can't seem to figure out whats wrong. Here's my code:


var number = 0;
var player = []; // array to hold caster's current status IDs
var enemy = []; // array to hold target's current status IDs
var i = 0;


while (number < 150) { // add the current status IDs of enemy to an array
if (b.isStateAffected(number)) {
enemy[enemy.length] = number;
enemy.length += 1;
number += 1;
} else { number += 1; }
}



number = 0; // reset status ID starting point to zero



while (number < 150) {  // add the current status IDs of caster to an array
if (a.isStateAffected(number)) {
player[player.length] = number;
player.length += 1;
number += 1;
} else { number += 1; }
}



number = 0;



while (number < 150) { // clear all statuses from target
if (b.isStateAffected(number)) {
b.removeState(number);
number += 1;
} else { number += 1; }
}



number = 0;



while (number < 150) { // clear all statuses from player
if (a.isStateAffected(number)) {
a.removeState(number);
number += 1;
} else { number += 1; }
}



for (i = 0; i < enemy.length; i++) { // add enemy's previous statuses to player
a.addState(enemy);

}







for (i = 0; i < player.length; i++) { // add player's previous statuses to enemy


b.addState(player
);

}





 
Are you saying you want to swap around the user's and the target's states?


enemy and player are arrays.  The addState method accepts one state, not an array.


However, why don't you just do something like this:

Code:
// save list of states away for later use
var aStates = a._states.splice(0);
var bStates = b._states.splice(0);

// clear states
a.clearStates();
b.clearStates();

// swap states
aStates.forEach(function(stateId) { b.addState(stateId); });
bStates.forEach(function(stateId) { a.addState(stateId); });
Are you saying you want to swap around the user's and the target's states?


enemy and player are arrays.  The addState method accepts one state, not an array.


However, why don't you just do something like this:



// save list of states away for later use
var aStates = a._states.splice(0);
var bStates = b._states.splice(0);

// clear states
a.clearStates();
b.clearStates();

// swap states
aStates.forEach(function(stateId) { b.addState(stateId); });
bStates.forEach(function(stateId) { a.addState(stateId); });



Thank you so much! :0


I'm bad at this lol.
Everyone always has more to learn 🙂   Don't feel bad.
Moving this to JS Support, since that's where it should be but closing because it's solved. If you want it reopen, please just report it and state why.
Reopened at OP's request.

Original thread: https://forums.rpgmakerweb.com/threads/switching-status-effects-with-target.70627/