AGI changes not factoring in for the current turn?

To get to the point, states (possibly direct parameter buffs as well, but I'm not sure) that alter the battler's Agility do not seem to have an effect on the current turn.

Now, obviously if it's an AGI boost on a battler that's already acted, there's not going to be any effect. That's fair enough.

But in theory, if we have the following battlers...
Actor A, with 20 Agility
Enemy A, with 16 Agility
Actor B, with 10 Agility

If Actor A attacks and inflicts a state that cuts Enemy A's Agility in half, then Actor B should (again, in theory) be able to act before Enemy A does, because 10 is greater than 8.

... yet, that doesn't seem to be happening. Even weirder is that I know this is actually exactly how it worked in MV (edit: Or... not? Well, then I know some plugins were able to achieve this, because I had successfully utilized this back with MV previously.). So this worked there, but doesn't seem to work here. For the record, I first tested with Visustella's OTB, then STB, and then with a new project with no plugins at all. Same results every time.

I'm curious to learn why, as well as if there's a fix or workaround (or if maybe MZ is somehow bugged?). I was developing systems under the assumption that this sort of thing worked the same as it did in MV, so being unable to do anything about this would be a pretty significant setback.
Even weirder is that I know this is actually exactly how it worked in MV (edit: Or... not?
Nope, not 😉

The action's speed is calculated at the beginning of the turn, when actions are selected. That's exactly how default MV worked also.

If you use a different battle system that doesn't store everything simultaneously, changes to agility should be reflected.

For the record, I first tested with Visustella's OTB, then STB, and then with a new project with no plugins at all. Same results every time.
That seems odd, because those three things function completely differently.

OTB actions execute immediately, so you wouldn't expect agility to play any role in that. But an agility change that's enough to affect the turn order should be reflected and make that battler's next turn come sooner.

STB actions also execute immediately, so you wouldn't expect agility to play any role in that. Per the plugin description, it "uses RPG Maker MZ's default non-TPBbattle system as a base. Action orders are determined by the battler's AGI values and they go from highest to lowest."

So, again, I would expect the order within a turn to be determined at the beginning and any changes would take effect in the next turn.

The trick with modifying how this works is you need to choose a battle system. Making what you want work with one of the VisuStella plugins could be problematic, because changing this will involve changing functions in the battle system to check for any change in turn order, and their code is obfuscated so we wouldn't know what to change or how to make our code 100% compatible.
I'm pretty sure this is the standard behaviour in the RPG Maker MV as well. By default the turn order is decided at the beginning of the battle turn and not updated in between actions.

I'm not sure if this would work with alternate battle systems, but in theory you could try to update the turn order between each battler:
Code:
/*:
 * @plugindesc
 * Update the turn order before a new battler takes action in battle.
 */
BattleManager.getNextSubject = (alias => function() {
    this._actionBattlers.forEach(battler => battler.makeSpeed());
    this._actionBattlers.sort((a, b) => b.speed() - a.speed());
    return alias.call(this);
})(BattleManager.getNextSubject);
I'm not sure if this would work with alternate battle systems, but in theory you could try to update the turn order between each battler:
I'm...not sure that will work as expected?

The default getNextSubject() uses shift() to get rid of the battler that just acted and return the next member.

If you reorder the array and then call the same code, it might shift() out a different battler who hasn't gotten a turn and put the old one back in order with no queued action anymore.

I haven't tried it, of course, so maybe I'm thinking through it incorrectly.
Nope, not 😉

The action's speed is calculated at the beginning of the turn, when actions are selected. That's exactly how default MV worked also.

If you use a different battle system that doesn't store everything simultaneously, changes to agility should be reflected.
Yeah, that's... weird. Maybe Yanfly's plugins changed how all that works? Because I know I got this working just fine in MV. But, I mean, I was using Yanfly, so... yeah.
That seems odd, because those three things function completely differently.

OTB actions execute immediately, so you wouldn't expect agility to play any role in that. But an agility change that's enough to affect the turn order should be reflected and make that battler's next turn come sooner.

STB actions also execute immediately, so you wouldn't expect agility to play any role in that. Per the plugin description, it "uses RPG Maker MZ's default non-TPBbattle system as a base. Action orders are determined by the battler's AGI values and they go from highest to lowest."

So, again, I would expect the order within a turn to be determined at the beginning and any changes would take effect in the next turn.
The weirdest part of that is that I was specifically using STB back in MV, and all of this worked how I said it did back then.
The trick with modifying how this works is you need to choose a battle system. Making what you want work with one of the VisuStella plugins could be problematic, because changing this will involve changing functions in the battle system to check for any change in turn order, and their code is obfuscated so we wouldn't know what to change or how to make our code 100% compatible.
Well, I had intended to work with OTB due to the ability to push turns around. And I'd still like to. Especially since there seem to be parameters that allow AGI alterations to affect the current turn, but they don't seem to do anything. AGI changes seem to only affect the turn after the "next". As in, there's the current turn order, the visible next turn order, and the invisible turn order for the one after that, and only that one ever seems to be affected (again, despite parameters existing in the plugin to affect the other two).

... although oddly enough, I tried updating my library the other day and noticed that passive states stopped working entirely (thankfully I backed that folder up first...). I know that's somewhat unrelated, but it's leading me to think that there's bugs causing things to not work as intended. But at the same time, I haven't seen anyone discussing this. Very confusing issue.
I'm pretty sure this is the standard behaviour in the RPG Maker MV as well. By default the turn order is decided at the beginning of the battle turn and not updated in between actions.

I'm not sure if this would work with alternate battle systems, but in theory you could try to update the turn order between each battler:
Code:
/*:
 * @plugindesc
 * Update the turn order before a new battler takes action in battle.
 */
BattleManager.getNextSubject = (alias => function() {
    this._actionBattlers.forEach(battler => battler.makeSpeed());
    this._actionBattlers.sort((a, b) => b.speed() - a.speed());
    return alias.call(this);
})(BattleManager.getNextSubject);
Holy moly, I think this actually works. I mean, I've only done cursory testing so far, but I don't see any issues yet.

Thank you! I can't even begin to explain how much of a life-saver this is.
The default getNextSubject() uses shift() to get rid of the battler that just acted and return the next member.
The array should only contain the battlers that did not have their turn yet. The battler that just acted is stored in _subject instead (and gets replaced with the battler that was shifted from the array).

... although oddly enough, I tried updating my library the other day and noticed that passive states stopped working entirely
No idea what happened there.
One oddity that I noticed in previous makers though was that changes to scripts (and probably plugins) would only take effect after you explicitely saved your project, which lead to some weird occurrances in battle test.
Also if you press F8 in test play you should see a notification if some plugins maybe could not be loaded.

Holy moly, I think this actually works. I mean, I've only done cursory testing so far, but I don't see any issues yet.
Glad to know it seems to help.
So after some more testing, I did find two issues with that plugin. (edit: I mentioned it before, but to be clear, I'm currently using the OTB system.)

1. the notetag commands that push battler actions around essentially have no effect now. Which... honestly, this is whatever to me. I was already experimenting with clever use of element rates to indirectly affect turn order to try and solve this earlier. And thanks to the plugin, they actually do seem to work now! You know, now that I technically no longer need it to, lol.

2. this one is unfortunately a bit more serious. The "next" turn order isn't properly reflecting AGI changes made. It only kicks into effect once "next" becomes "current". But then the new "next" does reflect said changes, so I'm not sure what to think.

I suppose the simple solution would be to move to STB and deal with it, but I do like being able to see what's happening next turn. To be clear, the AGI mechanics are FUNCTIONING as intended, just not DISPLAYING what the function actually is until that turn becomes the current one, but you're essentially being blindsided at that point.

Can anything be done about that? I know Visustella plugins are obfuscated, so this is probably a no, but I thought I'd ask anyway.
It should be mentioned that the script above was mainly aimed at the standard battle system, there is no guarantee it will work with a different turn order management.

Right now the script does not contain a way to distinguish whether a battler is in the wrong order because their AGI may have changed, random speed fluctuations or if they were specifically moved to the slot.

Speaking of random fluctuations, you may want to check whether battlers will randomly swap positions if multiple battlers have the same (or very similar) agility, since the standard speed adds a small random factor between 0 and 25% each time it is recalculated.
It is at least very likely that the script ignores some changes to speed calculation that the OTB introduces if that is an issue.

As you mentioned, VisuStella does not publicize their code, and the next turn preview is an original feature of the OTB, so your best chances would likely be to ask the original authors yourself.

A long shot alternative might be to emulate your own next turn order and use skill effects to move the other battlers around as needed.

Original thread: https://forums.rpgmakerweb.com/threads/agi-changes-not-factoring-in-for-the-current-turn.167587/