For loops not processing. [Solved]

Straightforward, nested for loops don't seem to be doing anything, and I can't for the life of me figure out why.

Code in question is:
Spoiler
var setTWGains = BattleManager.startBattle;
BattleManager.startBattle = function() {
setTWGains.call(this);
console.log('Start!');

for (id = 0; id < $gameParty.battleMembers(); id++) { // Uses ES5
console.log('Loop one!');
for (val = 0; val < $dataActors.length; val++) {
console.log('Loop two!');
var actor = $gameActors.actor($gameParty.battleMembers()[id]._actorId);
actor._healGain[val] = twHeal;
actor._buffGain[val] = twBuff;
actor._debuffGain[val] = twDebuff;
if (actor.isStateAffected($dataActors[actor].favstate)) actor._buffActive = true;
else actor._buffActive = false;
actor._debuffRemoved = false;
actor._hasDebuff = false;
actor._startHP = actor._hp;
}
}
console.log('Battle!');
};

And the console logs 'Loop one!' and 'Loop two!' never hit the console. I don't get any errors, but when I try to read the variables defined in here during the battle, they come up as undefined. So what am I overlooking? Because I swear this worked for awhile, and I don't remember changing anything about it XD.

Appreciate the time and help!

~ Zephyr
You never initialized the var itself (the id var) so it could have problem to initialize
You never initialized the var itself (the id var) so it could have problem to initialize

A good point (it's apparently been awhile since I've used a for loop XD), but didn't affect anything unfortunately. Hopefully it'll save me trouble down the road though!

Edit:
I've got other for loops without the var that work fine, so js must assume a declaration.
Hi, I'm not on my pc at this time and I can't recall what $gameParty.battleMembers() does. Could you try a console.log() of that and see it it returns a number? From the code I'm assuming it's an array, and maybe in the for line it's missing a .length ($gameParty.battleMembers().length).
Hi, I'm not on my pc at this time and I can't recall what $gameParty.battleMembers() does. Could you try a console.log() of that and see it it returns a number? From the code I'm assuming it's an array, and maybe in the for line it's missing a .length ($gameParty.battleMembers().length).

That did it, and that's what I changed! XD

I was previously using $gameParty.maxBattleMembers(), which returned a set number (4), but that error'd out if the team wasn't full. Switching it to .battleMembers() solved that issue, but started returning an array rather then a set number, as you pointed out. Adding .length was the solution.

Thanks for that! ^_^

Original thread: https://forums.rpgmakerweb.com/threads/for-loops-not-processing-solved.94772/