Problems with Drifty's "Equipment Optimizer" code

Okay so I wanted to do a common event, bound to a key (using yanfly plugin) that would optimize the entire party's equipment when the button is pressed. Like Drifty did in his game Legend of Driftwood. I even looked at a "tutorial" where he shows the code snippet used in that common event and I'm positive I've written it just like he has - but it doesn't seem to work for me.

Spoiler: The code snipped that is supposedly going to auto optimize your equipment
var length = $gameParty.allMembers().length;
for (var i = 0; i < length; ++i) {
var actor = $gameParty.allMembers();
If (actor) actor.optimizeEquipments();
}


The video tutorial can be found here (watch from ~19:32 and you get right to where drifty talks about the code):


Thank you for for reading. 😍
var length = $gameParty.allMembers().length;
for (var i = 0; i < length; ++i) {
var actor = $gameParty.allMembers();
If (actor) actor.optimizeEquipments();
}


You missed the "[ i ]"
var actor = $gameParty.allMembers()

so you need to place behind it like I did in the top part ^^
or it wont read " i " without any purpose.
@ShadowDragon
Thank you for pointing that out. I guess I'm a bit tired. I fixed it but... it still doesn't work for me? 😢

Here's a screenshot of the entire event. I guess it's easier to help if you have a clear picture of what's going on:
Spoiler: Screenshot of the common event
fCPebdo.png

I bet the problem is something obvious but my sleepy eyes just can't see it.
"if" needs to have a lowercase "i", try this instead~
Code:
var length = $gameParty.allMembers().length;
for (var i = 0; i < length; i++) {
  var actor = $gameParty.allMembers()[i];
  if (actor) actor.optimizeEquipments();
}
totally overreaded the "If" statement, sometimes you read to fast and notice it later on lowercase "if".
Nice catch on that on @caethyril ^^ (always keep your eyes open for the most tiny mistakes)
@caethyril
Wow, thank you. I totally didn't see that. Now it's finally working!

@ShadowDragon
You and me both. It's such a relief to finally have this feature working. Thanks for your help as well.
um ...

Code:
$gameParty.allMembers().forEach(function(actor) { actor.optimizeEquipments(); })
@Shaz
Oh snap. That code is way more clean (and works just fine). Thank you for bringing that to light. 😍
Thread closed IgnoreMe

Original thread: https://forums.rpgmakerweb.com/threads/problems-with-driftys-equipment-optimizer-code.112736/