RMMV Arrays in Battle Events (updated for clarity and ease of reading)


Sep 15, 2020
Reaction score
First Language
Primarily Uses
First, apologies if this isn't in the right place. It involves plugins, javascript, script calls, and eventing to one degree or another but I remain uncertain as to the best place to post this. If there is a better place please let me know and I'll gladly repost there.

TLDR: I'm trying to update, or at least check, an array from a battle event every turn. The code I have works perfectly, but only when I set the battle event to run just once per battle on turn 0. As soon as I set it to run every turn, the array no longer updates.

To make things even more confusing, while doing some testing this morning I realized that it only even works on turn 0 once per battle when I do a battle test from within RMMV. It doesn't work at all when I run the game and enter the battle naturally.

Using console.log() I've confirmed that the appropriate IF statements run every turn, but the array doesn't get updated. I'm assuming that there is some quirk of the way arrays function in the battle system that is preventing this, but I have no idea what that is or if there is a way to work around it. Any help, or even just information as to what this quirk of arrays may be, will be greatly appreciate.

That's the basic overview. Below you will find a fairly exhaustive breakdown of my current setup.

The Concept
Using a combination of Yanfly's Row Formations and Hime's Enemy Reinforcements I'm trying to create a battle in which enemies spawn off screen and then slowly advance across the battlefield until they are close enough to attack the party characters. The basic setup was quite trivial and I soon had enemies spawning more or less randomly and moving across the screen.

My first problem came when I saw that there was no way easily limit this movement and all enemies would eventually accumulate in the front row. With enemies spawning regularly this presents a problem in that the player can easily become overwhelmed. On top of that, the enemy battlers often overlap each other in ugly and confusing ways.

My first step was to implement conditional States, courtesy of Yanfly's Row Formations. A unique State was created for each row that would check the total number of enemy battlers in the row ahead of of them and temporarily seal the movement skill if that row was full.

This worked great, except for the fact that there was no way to distinguish which slot in a given row was open, only that it wasn't full. So the first enemy then able to move would do so, often overlapping another enemy in the process.

I decided that there must be a way to define my own "columns" and keep track of how many enemies were in each and what their positions were. The basic structure of the battlefield then looks something like this:
The red section is the enemy side while the green is the party side. I'm not doing anything fancy for the party side so for now I've just included this for the sake of portraying a complete picture.

I know this is backward from the way we tend to think of rows and columns, but the rows are defined by Yanfly's Row Formations so this is what we end up with.

The Code
On the first page of my troop battle event I define the following:
// zSpawnRNG
$gameVariables.setValue(22, [0, 0, 0, 0, 0]);

// Column One (Top)
$gameVariables.setValue(25, [1, 0, 0]);

// Column Two
$gameVariables.setValue(26, [0, 0, 0]);

// Column Three
$gameVariables.setValue(27, [2, 0, 0]);

// Column Four
$gameVariables.setValue(28, [0, 0, 0]);

// Column Five (Bottom)
$gameVariables.setValue(29, [3, 0, 0]);
zSpawnRNG is for keeping track of which columns are available to spawn enemies in. While Columns 1-5 are for keeping track of the enemies spawned in them. At the start of the battle columns 1, 3, and 5 have enemies in them and the numbers defined here correspond to the enemy battler indexes within the troop.

On a separate page, once per turn, I run the following:

Variables 30-34 are defined on the same page as the arrays themselves, running on turn 0 of the battle, and are just there keeping track of how many enemies are in each column as they approach. I'll increase those numbers by 1 when an enemy spawns, and decrease them by one when an enemy dies.

Though I hope to keep close enough track of spawned enemies to actually be able to prevent them moving if there isn't an open spot in the same column of the row in front of them I believe that a solution to the issue of overlapping enemies may be as simple as making sure the enemy spawns are staggered and that the spawns prioritize columns that are already empty or have the fewest number of enemies.

The battle event looks at each column and updates variable 22 (zSpawnRNG) with each empty column (1-5).

Once that's done it will pick one of the empty columns at random from zSpawnRNG and spawn an enemy there. That code has been removed for testing purposes at this time.

Eventually I hope to be able to keep track of all the spawned enemies indexes and use that to determine where in each column a given enemy is, preventing them from moving if the space in the row in front of them isn't open. But if this first phase works well I may not even have to go that far.

If worse comes to worse, I can probably just break the arrays up into individual variables. My project isn't that big and I think I can get away with it, but I know there's got to be a more efficient way to accomplish this. Any advice, suggestions or help would be greatly appreciated.

Last edited:


Sep 15, 2020
Reaction score
First Language
Primarily Uses

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Dad's watching a WWII documentary while I work on some cool assets for my games. I just love RPG Maker!
Also Happy Halloween! Dad's friend won't be coming unfortunately, but Dad will still be taking me to Boxi Park to have some fun tonight! I'll be posting a video on my YouTube channel of the show, and I'll be sure to post a link here.
"Nightmares exist outside of logic and there's little fun to be had in explanations. They're antithetical to the poetry of fear. In a horror story the victim keeps asking why, but there can be no explanation and there shouldn't be one..." - Stephen King
I feel people seek explanation and demand it sometimes in games, but in the horror genre, well, maybe you shouldn't have one. Silent Hill 1 comes to mind...
Managed to implement QSprite.

Always double check your plugin order.

Finally! I've been puzzling over why it wasn't working for two days now. Turns out all of my calculations were correct, I just forgot to give some events hitboxes. :kaoswt: Now my randomly generated maps check for collision errors, and move stuff around in real time if they finds any. :LZSexcite:
--- OP Candy ---

Kids: Trick Or Treat!
Hero: Alright,here's the Candies (Give A Bunch Of Candy).
Kids: Thank you,Mister! (Running)
Hero: How cute they are…
F.Archer: Did you give them a OP Candy,accidently?
Hero: Huh?

Forum statistics

Latest member