Script calls resulting in error?

hi i want to switch two states out after an evented timer finishes counting down, but trying to use $gamePartyMembers()[x] and $gameActors.actor()[x] just results in an error
using a set integer (so like, $gameActors.actor()[0].addState(34)) also results in an error. It doesn't work on a clean game either. what am i doing wrong??
1707402332607.png
1707402111278.png
There's no such thing as $gameActors.actor()[i] - where did you see that syntax?

The actor() method does not return an array (and it requires an argument), and i is not an actor ID.

It should be $gameParty.members()[i] just like you typed on the line above.

You can also make this more efficient by using JavaScript's built-in array methods. The entire script call could be:
Code:
$gameParty.members().forEach(actor => {if (actor.isStateAffected(33)) {actor.removeState(33); actor.addState(34)})
additionally, you messed up your index borders.

0 to size has one more element/actor than the size itself has, so one actor will always be undefined.
also, I agree with ATT_Turan, $gameParty.size() start with 1, not 0.
for (var i = 0; i <= memb; i++) also throw an error on "<=" instead of "<" alone.
$gameActors.actors() cannot work as it isn't define before, so it failed.

the way ATT_Turan said is more effecient and cleaner to read what it does if you know
Javascript 😉
additionally, you messed up your index borders.
0 to size has one more element/actor than the size itself has, so one actor will always be undefined.
True, I didn't notice that - if you stuck to doing it in a for loop, it should be < not <=
There's no such thing as $gameActors.actor()[i] - where did you see that syntax?

The actor() method does not return an array (and it requires an argument), and i is not an actor ID.

It should be $gameParty.members()[i] just like you typed on the line above.

You can also make this more efficient by using JavaScript's built-in array methods. The entire script call could be:
Code:
$gameParty.members().forEach(actor => {if (actor.isStateAffected(33)) {actor.removeState(33); actor.addState(34)})
This is entirely valid, but just to inject a personal preference since I avoid forEach like the plague due to how comparatively expensive an operation it is:

JavaScript:
for (const actor of $gameParty.members()) {
  if (actor.isStateAffected(33)) {
    actor.removeState(33);
    actor.addState(34);
  }
}

is slightly more efficient. ^_^
I avoid forEach like the plague due to how comparatively expensive an operation it is:
Also avoids dating like the plague due to how expensive an operation it is. 😉
Also avoids dating like the plague due to how expensive an operation it is. 😉
Kytt and I have a date night at least every month, actually (ironically, we actually do our best game planning while we're out for dinner). 😛
Kytt and I have a date night at least every month, actually
Yeah, she told me your idea of "cooking for her" involves Cup o' Noodles.

Sorry, I'll stop the random joke tangent in someone else's support thread 🤣
There's no such thing as $gameActors.actor()[i] - where did you see that syntax?
now that you mention it I don't even remember lmao, though i probably mixed two parts of the mz script call doc up with each other
This is entirely valid, but just to inject a personal preference since I avoid forEach like the plague due to how comparatively expensive an operation it is:

JavaScript:
for (const actor of $gameParty.members()) {
  if (actor.isStateAffected(33)) {
    actor.removeState(33);
    actor.addState(34);
  }
}

is slightly more efficient. ^_^
this worked perfectly! thank u all

Original thread: https://forums.rpgmakerweb.com/threads/script-calls-resulting-in-error.165576/