Target's attack to a variable

I'm trying to log an enemy's attack value to Variable #0001 in order to compare it to the average Party member attack to give an indication of the monster's strength.

However, I'm having issues with the script to pick up on the target's attack rather than just enemy #1, #2, #3 etc. which can be done without any scripting.

o36JepN.png


When I used this I get a "param not defined" error. But I can't work out for the life of me what it should be instead :c.
try () instead of [] - If I remember correctly someone posted somewhere that param is a method and not an array...
Hmm seems the same.

Here's the error, btw. On second glance maybe the param bit is correct and its the part before?... idk

7OTEudN.png
Yep, it's the bit before. You're getting cannot read param property of undefined. That means $gameTroop.members()[target] is undefined.
So that means target is undefined, which means targetIndex is undefined, which means your targetIndex script call is wrong.

My guess is that there's no action to be read because you're trying to do that during the action selection phase.
Try a console.log(BattleManager._action) and it should return undefined if I'm right.

I don't get what exactly you want to achieve so I can't really help much more.
Yep, it's the bit before. You're getting cannot read param property of undefined. That means $gameTroop.members()[target] is undefined.
So that means target is undefined, which means targetIndex is undefined, which means your targetIndex script call is wrong.

My guess is that there's no action to be read because you're trying to do that during the action selection phase.
Try a console.log(BattleManager._action) and it should return undefined if I'm right.

I don't get what exactly you want to achieve so I can't really help much more.

I put your script in the line above and it didn't error, still the param error from before.

This is the event that uses this info, if it helps at all:
O3qhZL0.png
the problem is when does this event run?
The target index only exists after the engine has selected a target for the enemy, and according to the description if you get that error, then the engine has not yet selected that target.
That script call logs the current action in the console. It doesn't get rid of the error or makes another.
What I want to see is what the console shows after you put that script call and it runs.

This will tell us if Andar is right or not.
the problem is when does this event run?
The target index only exists after the engine has selected a target for the enemy, and according to the description if you get that error, then the engine has not yet selected that target.

It runs from a common event from a skill. I thought common events run last in a skill anyway - unless the target is wiped before then? Although maybe the target is wiped by then?...

Maybe I'll just give my [Marker] state another use :c.
no - common events run last after everything in the battle.
First all actions are selected (selection phase)
Second all actions are executed (that is when you see the battle messages)
And after all that is past, short before the battleturn ends, the common events called by the skills are executed.
@Andar What?
Test it yourself, in a new project add a common event trait to skill 1 attack and have everyone attack.
In the common event add a message call.
You'll see the message triggers after each action and not at the end of the turn.
If that is the case, then they changed the mechanic from Ace.

Original thread: https://forums.rpgmakerweb.com/threads/targets-attack-to-a-variable.77799/