When does the enemy choose their target and action?

I have a quick question based in targeting and action timing.

So I know HOW the enemy chooses it’s target and action, my question is WHEN does this take place?


For example, are all enemy actions selected at the start of the turn? So for instance once, the player selects all of their actions (assuming the default battle system is being used) and once that last action is selected, every enemies action is then determined and played out?

Or do they determine their action as their turn comes up? For example, the turn order is playing out, and as it becomes slime a’s turn, the action ans target is selected?

I assume from my looking at the code that it’s probably the former, but I’m not 100%.

And if it is the former, I was wonder how difficult it would be to change it to the latter? It may be cool for the enemy to react to changes in target rates In real time.

I assume of course it’s not easy 🙂

Thanks for taking the time to look at this!
all battleturns in the turnbased battle are divided into two phases - decision phase and action phase.

the enemies decide their actions at the same time as the player does.

THEN, between the two phases, the action order is determined.

all actions get a speed number that is determined by actor.agi plus skill.speed plus a random percentage. After that the actions are sorted highest to lowest.

that is why all selection has to be done first - you can speed up the action order of a skill by giving it a highe speed number, and that counts for both actor and enemy.
all battleturns in the turnbased battle are divided into two phases - decision phase and action phase.

the enemies decide their actions at the same time as the player does.

THEN, between the two phases, the action order is determined.

all actions get a speed number that is determined by actor.agi plus skill.speed plus a random percentage. After that the actions are sorted highest to lowest.

that is why all selection has to be done first - you can speed up the action order of a skill by giving it a highe speed number, and that counts for both actor and enemy.
Yup, just as I expected.

So, Basically changing the target rate during the turn won’t do anything until the next round of battle? Because If the targets are predetermined before the round start, their targets must be as well?


The way you outlined it makes perfect sense, thank you.
I don't know that, which is why I didn't mention it.

the skill needs to be selected at decision phase.
the target might be selected at skill execution instead, but I haven't checked that part of the code in a long time.
I don't know that, which is why I didn't mention it.

the skill needs to be selected at decision phase.
the target might be selected at skill execution instead, but I haven't checked that part of the code in a long time.
No worries, you’ve been very helpful as always.

I’ll dig some more in the code as well.
So, Basically changing the target rate during the turn won’t do anything until the next round of battle?
Correct.

IIRC, I made a change in my enemy AI code back then so before it takes a turn, it re-evaluates the skill condition before acting. But by default, it behaves as you expected. Mainly because when I use two times or more actions (and custom script condition for the skill), the second attack did not re-evaluate if it was still valid or not.
Correct.

IIRC, I made a change in my enemy AI code back then so before it takes a turn, it re-evaluates the skill condition before acting. But by default, it behaves as you expected. Mainly because when I use two times or more actions (and custom script condition for the skill), the second attack did not re-evaluate if it was still valid or not.
Thanks for confirming!

Ideally, I would like the enemy to re-evaluate the target based on how the target rate changes in the turn. So if mid turn some used a taunt skill, or change their target rate the enemy would act accordingly

Now, I’ll try to figure that out haha

Original thread: https://forums.rpgmakerweb.com/threads/when-does-the-enemy-choose-their-target-and-action.151299/