Battle Log not Showing State change with addState Script

Hello, this is my first game and first post on this forum.
I am using this script to add states to enemies, from a common event
$gameTroop._enemies[n].addState(13)

This works for giving the enemies the state exactly as it should. However the battle log does not display the "If an enemy is afflicted with the state" message. If I add the state the more normal way with effects inside skills/items, then the message shows correctly. It is only when adding the state from a common event that the message doesn't work.

I see this message from the DevTools window. It looks like that is where the problem is, but I have no real idea what it means or how to fix it.
Script Call Error VisuMZ_0_CoreEngine.js:6907 TypeError: Cannot read property 'addState' of undefined at eval (eval at Game_Interpreter.command355 (rmmz_objects.js:11252), <anonymous>:2:24) at Game_Interpreter.command355 (rmmz_objects.js:11252) at Game_Interpreter.<computed>.<computed> [as command355] (VisuMZ_0_CoreEngine.js:6907) at Game_Interpreter.executeCommand (rmmz_objects.js:9621) at Game_Interpreter.update (rmmz_objects.js:9526) at Game_Troop.updateInterpreter (rmmz_objects.js:5848) at Function.BattleManager.updateEventMain (rmmz_managers.js:2379) at Function.BattleManager.updateEvent (rmmz_managers.js:2372) at Function.BattleManager.update (rmmz_managers.js:2335) at Scene_Battle.updateBattleProcess (rmmz_scenes.js:2977)

Disabling all plugins doesn't change anything.
I know how to add the messages manually with SceneManager._scene._logWindow.addText(text)
But that seems very messy and not ideal.
The error is saying you are trying to add a state to an enemy that doesn't exist. So there is something wrong with your script call.

"It is only when adding the state from a common event that the message doesn't work."

Is this really true? Or is it because you're trying to add the state via a script call? What if you use the Change Enemy State event command (3rd page)? How are you setting the value of n? If you got that command from the script call list, those are not meant to be simply copy/pasted - you have to ensure that n is either set to a value correctly, or replace n with a number.


Can you please show a screenshot of your common event so we can see exactly how you are calling it?
Sorry for the late reply

The error is because of the loop I'm using, so if there's less than 8 enemies It keeps trying to add the state to non-existent enemies. I understand that now, and I will fix it.
With 8 enemies I do NOT get the error message. So that isn't the issue.

This is the common event I am using. It really does work correctly in game. I also attached a screenshot of the game, so you can see the enemies have the stunned status symbol above their heads.

I tried removing the script section, and replacing it with Change Enemy State event command (3rd page). This gives the same result, the enemy is stunned but there is no battle message stating they are stunned.
Script.JPG
Gamecap.JPG
Arrays start with element 0. So if you want enemy 7, it's $gameTroop._enemies[6], not $gameTroop._enemies[7].
Alright thank you I have the loop error fixed.
However I am back to square one. I would like the battle log to display the state change. After reading some other posts such as this one, this is not a problem with my game. It's just how RPG Maker is intended to work. addState does not trigger the battleLog,

The closest I can get to what I want to do is using forceAction with a dummy skill that just stuns the enemy.
The only problem I have with this is that it causes a casting(?) animation each time. It would be extremely annoying for the player after several battles. I don't know how to get rid of this. I have all the cast animations set to 0 in VisuMZ battle core.

Writing the message manually like this is a last resort but I can deal with it if there's no better option.
var text = "Your text goes in there." SceneManager._scene._logWindow.addText(text)
Instead of this, Is there some kind of command that tells the battle log a state was changed and to display it just like it would if it happened directly from a skill instead of common event?

CorrectScript.JPG

(I commented out that one line just to save it, doesn't affect the code)

Original thread: https://forums.rpgmakerweb.com/threads/battle-log-not-showing-state-change-with-addstate-script.137451/