Could use some help with common events: "isStateAffected" is undefined within them?

Greetings,

I am trying to create a skill that has varying effects depending on what States you have active on the target. In this example, if the target has state 34 and state 70, I want the skill to deal triple damage. I know that part is all working fine, as I've tested it with a different conditional branch.

My issue is that for whatever reason, my conditional branch script to check if the target has a state is not functioning. I'm probably missing something silly and simple but I've been at this for hours now and scoured the net and can't figure this out for the life of me.

Here is the event:

common event help 1.png


Whenever I try to use the skill in a battle, I get a console error:

Untitled.png


I'm very confused as to why isStateAffected is throwing an error for being undefined, and yet I can use a regular conditional branch event command to check if an enemy has a state just fine.

Is there something special I need to be doing to get this script to work?

Any help would be greatly appreciated 🙂. Thank you in advance,

-Niniann
It's not saying that isStateAffected() is undefined. It's saying properties of undefined - specifically isStateAffected().

So whatever value is in variable 29, it's not a valid troop index.
Everything works well except for variable 29, which doesn’t return the correct index.

The data/Index should range from 0 to 3 (or adjust based on the number of enemies you're facing).

The issue is that the variable isn't receiving the correct information because no enemy was targeted previously.
How about using or forcing a skill on the same enemy before searching for the enemy's ID?
This way, your variable will correctly store the data.


I’m not sure if you can check the index in real-time, but maybe you can.
Ahhh, thank you both very much. I will get that part fixed up.

Cheers,
-Niniann

Edit: Wanted to post here with the solution to this issue in case someone stumbles upon this thread in the future.

I found a little snippet of code caethyril had written years ago for another on the Steam forums here:

The code is as follows:
var rememberTargetIndex = 0;
var _Game_Action_apply = Game_Action.prototype.apply; // alias
Game_Action.prototype.apply = function(target) {
rememberTargetIndex = target.index();
console.info(rememberTargetIndex); // test
_Game_Action_apply.call(this, target); // callback
};

By saving this into a plugin (and setting rememberTargetIndex = 29, since that's the variable I want to use), the game will now record target selection into the variable.

I can then reference that variable in common events to investigate the target's current States and apply different effects depending on the target's State.

Thank you all again for your assistance. Take care out there 🙂.

Original thread: https://forums.rpgmakerweb.com/threads/could-use-some-help-with-common-events-isstateaffected-is-undefined-within-them.169667/