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

Novic

Warper
Member
Joined
Sep 15, 2020
Messages
4
Reaction score
0
First Language
English
Primarily Uses
RMMV
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:
1601144635868.png
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:
Code:
// 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:
1600973798846.png
1600973855711.png

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.

Thanks!
 
Last edited:

Novic

Warper
Member
Joined
Sep 15, 2020
Messages
4
Reaction score
0
First Language
English
Primarily Uses
RMMV

Latest Threads

Latest Posts

Latest Profile Posts

Today I drove through my city of 100,000+ people during rush hour and the streets were nearly empty. Just so I could go get my favorite burger. There a dental assistant (she said that's her other job, even though I didn't ask) took my order and handed me a burger. I know it's bad out there... But wow, she's either atrocious with her money, or "it really be like that".
Chilling out while toodling around someone's painstaking Minecraft recreation of Disneyland. It is mind-boggling and probably as close as I'll ever be to going.
>Testing with fonts change.
>Tries installing a plugin. Doesn't work.
>Tries changing the plugin commands. Doesn't work.
>Tries installing another plugin. Doesn't work.
>Changes a few more plugin commands. Doesn't work.
>Goes directly to the gamefont file and changes the src. Works.

YYEEEAAAAHHHAAAA

Perseverance is key, bois and girls.
What Reviews say on RPG Maker MZ?
Looking back at some sketches, and game design documents on my PC dated summer of 2015. I started development with the release of MZ, but in 2015, I felt a strong desire to make a game out of the blue. I remember feeling sad for no apparent reason, and all these ideas rushed into my head. Now that I think about it, since that day, everything has become easier to do on my PC . . . it’s very creepy.

Forum statistics

Threads
107,809
Messages
1,032,364
Members
139,954
Latest member
Ocren
Top