RMMV Your Experiences with Lag

Hi everyone,

I am in the process of eventing a very large farming system in which each farm plot is its own event. Each plot can, depending on season (variable), be planted with up to 6 different plants which each have 2-5 growth stages.

Each of these stages is its own event page, and so I am arriving at a very high number of event pages (about 70+ per event). As I understand there are no MV plugins that allow additional event pages (correct me if this is wrong), this is made possible by editing the JSON file according to this Steam thread and is working fine.

In reference to most Harvest Moon / Stardew Valley etc games, there will be about 1000 farm plots total in the end.

I am further using Yanfly's Self Switches and Variables for the coding so the actual overall number of variables in the game will be much lower than the number of farm plots, in case this affects processing.

Before I go ahead and code 1000 plots (especially things like "plants growing if watered while you sleep" and fun tidbits like that), I wanted to ask for your own experiences with lag in RMMV games. My worry is that the game will struggle once the farm map is loaded, or perhaps during the sleep common event when all those processes are running; and I would like to hear about your ways to minimise these issues BEFORE I spend dozens of hours on programming them.

Any experiences are welcome, including "I've never had issues with lag". It would be great if you could vaguely mention your system (ie laptop, desktop computer, OS version such as Windows 10, even core and RAM and so on if you want) as well.

Some pointers of what I am trying to achieve:
  • Up to 1000 farm plots that can all be planted (have a plant sprite "character" with a simple movement route) at the same time, on the same map
  • Each of these 1000 events has 70+ pages (each page itself is very minimal to be fair)
  • When watered, the farm plot changes to have dripping effects. I have two ideas of how to achieve this, both have been tested and work fine:
    • Either: Each "stage" has two sprites/event pages, one standard and one watered (same but with drips) activated by a self switch. This is working fine, but adds a significant number of pages;
    • Or: I have been using Yanfly's Icons On Events plugin to add a drip icon on each plant that has been watered, via a separate master-event (parallel process). This is also working fine, but I worry there will be some lag (the icons appear on the plants one at a time in the order of listing in the event, and for 1000 plants that will take quite some time to finish every time the map is entered) - I think this is the worse option to be fair
If you ever had a project with LOTS of moving parts on the same map, I welcome your feedback and opinions on this. I am really unsure what actually causes lag on RMMV, if anything (I've never really experienced it myself).

Thanks in advance for your feedback, and for reading all this!
Lui
I haven't made anything with this many events at once - if I was building something like this, I'd probably just define a large region and have a single script manage what's in each plot and drawing sprites as needed.

But one suggestion I do have is to use sprite rotations / stepping frames as stages. Assuming your plants aren't going to be walking around, you could just have one page per plant type, with the spritesheet having all the stages as parts of the walking animation. As it grows you can simply "rotate" it or advance the stepping animation by a frame.
1 - The sheer number of events on a map has basically 0 effect on lag. Lag is created by computer processing - e.g. many parallel events trying to do things every frame.

2 - I don't see how the number of event pages could have any effect on lag. Checking 70 elements of an array (to see if conditions are met) is a fart in the wind for a computer processor.

3 - I strongly doubt that the way you're implementing this is the best, most efficient way. I would look at an event spawning plugin for the different kinds of plants or seasons or something before I considered an event getting to 70 pages to account for all possibilities. I don't want it to come across as at all patronizing, but that's unfathomable to me. 😉

(each page itself is very minimal to be fair)
If that's the case, why do they need to be separate pages? You can use conditionals within an event page for similar conditions that need to be treated slightly differently. Generally speaking, the reasons you need to use a different event page are to change the event's image or one of its other settings in the bottom left (trigger type, autonomous movement, etc.).
One thing to point out is that the logic quality is much more important than the number of parallels.
A single badly designed parallel process can lag even the most powerfull computer, but with a good logic there is usually no problem running hundreds of events.

That said, 1000+ events is pressing the limits, and you should make sure that your logic design is checked before using it.

has 70+ pages (each page itself is very minimal to be fair)
70+ pages is very questionable in my opinion, and you might consider optimizing them.
the only reason for additional pages I can think of would be different plants, (sprites) but that number is a bit high for that.

I strongly su8ggest that you share your plans for those events before you implement them, just to make sure that nothing goes wrong when implementing it.
Thank you all so much for your responses so far!
I haven't made anything with this many events at once - if I was building something like this, I'd probably just define a large region and have a single script manage what's in each plot and drawing sprites as needed.

But one suggestion I do have is to use sprite rotations / stepping frames as stages. Assuming your plants aren't going to be walking around, you could just have one page per plant type, with the spritesheet having all the stages as parts of the walking animation. As it grows you can simply "rotate" it or advance the stepping animation by a frame.

Thank you for the suggestions. What do you mean by "define a large region and have a single script manage this" please? I assume you mean define the field as Region ID X and then have a plugin do something on that region ID if the player does ABC but I am not sure how it would be drawing the right sprites for this.

Re the second point, at the moment, each event page is for a new sprite & to check if the plant is watered, and not much else. From what I understand, this will not massively affect processing on that map (?) whereas your idea to have one page per plant type would require parallel events, no?


1 - The sheer number of events on a map has basically 0 effect on lag. Lag is created by computer processing - e.g. many parallel events trying to do things every frame.

2 - I don't see how the number of event pages could have any effect on lag. Checking 70 elements of an array (to see if conditions are met) is a fart in the wind for a computer processor.

3 - I strongly doubt that the way you're implementing this is the best, most efficient way. I would look at an event spawning plugin for the different kinds of plants or seasons or something before I considered an event getting to 70 pages to account for all possibilities. I don't want it to come across as at all patronizing, but that's unfathomable to me. 😉


If that's the case, why do they need to be separate pages? You can use conditionals within an event page for similar conditions that need to be treated slightly differently. Generally speaking, the reasons you need to use a different event page are to change the event's image or one of its other settings in the bottom left (trigger type, autonomous movement, etc.).

Thank you as well re 1&2!
I am a bit worried you're right about point 3 but I haven't found a better method for what I'm doing yet 🙄 I will share what each event looks like below, maybe that clarifies things?

The reason for so many pages is, as I said, that each plant stage for each plant is its own image (for example, Tomato has 3 growth stages = 3 sprites; same with Potato; Aubergine has 4; and so on).

One thing to point out is that the logic quality is much more important than the number of parallels.
A single badly designed parallel process can lag even the most powerfull computer, but with a good logic there is usually no problem running hundreds of events.

That said, 1000+ events is pressing the limits, and you should make sure that your logic design is checked before using it.

70+ pages is very questionable in my opinion, and you might consider optimizing them.
the only reason for additional pages I can think of would be different plants, (sprites) but that number is a bit high for that.

I strongly su8ggest that you share your plans for those events before you implement them, just to make sure that nothing goes wrong when implementing it.

Thanks again for your input as well. I think I answered some of it above already.

To streamline things, I have been looking at some spawn plugins (like the one by Galv) but I am struggling to get that to implement all the bits I want it to do. Especially the bit where the plant "grows" when the player goes to sleep. I am currently checking each event's self switch called "watered" during the sleep event and if yes = add +1 to the self variable for the plant in question. Not sure how this would work if the event may or may not be spawned depending on player action though. Maybe I am just not understanding the spawn plugin options that are out there correctly.

Here is what basically every single of the 70+ event pages will look like for the events, excepting the "planting" and the "harvesting" pages. Like I said, SUPER simple, the only differences will be
  1. The sprites
  2. The variable (to display the plant in question - example: Self Var Carrot 1 = seed, 2 = sprout, 3 = plant and so on)
  3. Perhaps the movement route.
Explanation: If variable "Moisture" (Placeholder name for carried water) is >1, then the plant is watered at player touch. Ignore the comments, they need to be updated a bit.

Examplepage.PNG


Because it works with Self Variables and Self Switches (thanks Yanfly!), every single event is identical and I just have to copy paste it 1000 times (or however much). During the sleep event, I then do the following:
  1. Set Self Variable Carrot for the sleep event = this.getselfvariablevalue(mapID, EventID, VarID)
  2. Same with the self switch for Event ID 1
  3. If self switch water = ON, add +1 to the self var X for the event in question
  4. Repeat for Event ID 2 and so on (this is the bit that will actually take time to amend for each event)
This works fine - I've tested it extensively, but it's perhaps not very elegant...

Thanks again for your input <3
Lui
What do you mean by "define a large region and have a single script manage this" please?
Essentially I mean just having a plugin handle all of it, without using the event system at all - detecting any attempts to interact with a tile in a region, doing logic with JavaScript, and drawing custom sprites as plants. Not an approach I'd actually recommend unless you do know how to do that.

Re the second point, at the moment, each event page is for a new sprite & to check if the plant is watered, and not much else. From what I understand, this will not massively affect processing on that map (?) whereas your idea to have one page per plant type would require parallel events, no?
That wouldn't require parallel events, just moving the logic for selecting the correct sprite to the sleep event. Assuming I'm understanding correctly that it's the only time when plants can change stages.
This should make lag a tiny bit better, since you're making those checks only at the sleep event instead of every time a variable changes, but the main advantage is probably just being able to access all the pages in the editor.

I'd also strongly second @ATT_Turan's suggestion for looking into an event spawning plugin - having just as single prototype event for each plant that gets automatically copied by the plugin where needed sounds like a much nicer way to handle all of this.
Here is what basically every single of the 70+ event pages will look like for the events, excepting the "planting" and the "harvesting" pages. Like I said, SUPER simple, the only differences will be
  1. The sprites
  2. The variable (to display the plant in question - example: Self Var Carrot 1 = seed, 2 = sprout, 3 = plant and so on)
  3. Perhaps the movement route.
Then you really don't need so many different pages.

Use the editor's quick event creation to make a door or a chest and look at how they work. Your event image is loaded from a character sheet, so you can use facing commands to change the image by putting them on different rows of that sheet.

You can have 4 different kinds of plant covered by one event page by simply telling it previously to face up, down, left, or right as appropriate for the kind of plant. Then the rest of the logic is the same (or with slight differences that you account for in conditionals).

Additionally, I stand by my previous recommendation - this is exactly the kind of thing event spawning plugins are made for. You don't need to have one event that can accommodate every possible thing in the world, just make one template for each kind of plant then spawn in the correct individual one.
Essentially I mean just having a plugin handle all of it, without using the event system at all - detecting any attempts to interact with a tile in a region, doing logic with JavaScript, and drawing custom sprites as plants. Not an approach I'd actually recommend unless you do know how to do that.

That wouldn't require parallel events, just moving the logic for selecting the correct sprite to the sleep event. Assuming I'm understanding correctly that it's the only time when plants can change stages.
This should make lag a tiny bit better, since you're making those checks only at the sleep event instead of every time a variable changes, but the main advantage is probably just being able to access all the pages in the editor.

Hmm, definitely not something I am familiar with although it sounds super neat as an idea. But that is unfortunately going over my head.


Then you really don't need so many different pages.

Use the editor's quick event creation to make a door or a chest and look at how they work. Your event image is loaded from a character sheet, so you can use facing commands to change the image by putting them on different rows of that sheet.

You can have 4 different kinds of plant covered by one event page by simply telling it previously to face up, down, left, or right as appropriate for the kind of plant. Then the rest of the logic is the same (or with slight differences that you account for in conditionals).

OK, LOTS of food for thought here that is definitely making me think I've been looking at this stuff so long I lost sight of the forest for all the trees. Thank you so much, again! I got so stuck thinking that the different stages HAD to be different event pages because... they look different... but you're of course completely right and they can just share a page with different movement routes.

Additionally, I stand by my previous recommendation - this is exactly the kind of thing event spawning plugins are made for. You don't need to have one event that can accommodate every possible thing in the world, just make one template for each kind of plant then spawn in the correct individual one.

I'd also strongly second @ATT_Turan's suggestion for looking into an event spawning plugin - having just as single prototype event for each plant that gets automatically copied by the plugin where needed sounds like a much nicer way to handle all of this.

I would definitely love to do it like this! The only thing I can't wrap my head around is how to make this work with the sleep event though. At the moment, the sleep event calls to every existing farm event to check its self variables - which only works because I know the farm event IDs beforehand. (ie, they are IDs 1-1000.) I don't see how this would work with an event spawner which presumably would have IDs all over the place. Or am I missing something really obvious here again? :[]
I don't see how this would work with an event spawner which presumably would have IDs all over the place.
Depending on the plugin you might be able to specify exactly which IDs to use for the spawned events. Or you could do this for every event in $gameMap.events() except the ones you made yourself (i.e. are not plants).
I don't see how this would work with an event spawner which presumably would have IDs all over the place. Or am I missing something really obvious here again? :[]
You know, from the plugin parameters, which IDs spawned events have.

But yeah, it would be a very simple line of code for you to ask for help with instead.
Hmm, definitely not something I am familiar with although it sounds super neat as an idea. But that is unfortunately going over my head.




OK, LOTS of food for thought here that is definitely making me think I've been looking at this stuff so long I lost sight of the forest for all the trees. Thank you so much, again! I got so stuck thinking that the different stages HAD to be different event pages because... they look different... but you're of course completely right and they can just share a page with different movement routes.





I would definitely love to do it like this! The only thing I can't wrap my head around is how to make this work with the sleep event though. At the moment, the sleep event calls to every existing farm event to check its self variables - which only works because I know the farm event IDs beforehand. (ie, they are IDs 1-1000.) I don't see how this would work with an event spawner which presumably would have IDs all over the place. Or am I missing something really obvious here again? :[]
You could do it by event notetag, i.e. loop through all the events on the map, if it has <x> notetag, do this, if it has <y> notetag, do that.
Thank you again all of you!
I will continue to tinker with this.
Lui
You know, from the plugin parameters, which IDs spawned events have.

But yeah, it would be a very simple line of code for you to ask for help with instead.

Me again. As I am using Galv's event spawner there are no pre-defined plugin parameters for the event ID, it seems to just use whichever one is next free. It is then possible to check the ID of the last event with this script call:

$gameMap._lastSpawnEventId

So theoretically, each time an event is spawned, I can check its ID and save it to a variable. However, I then run into my next problem, as I don't know how to assign it to a different variable each time, and more importantly, how to check this variable with a different event later (during sleep) if I don't know what it is.

Ideally, I would predefine a set of variables (for example, 1-1000) and then automatically assign the ID value to whichever first one in that range is currently 0. This way, I can still check the pre-defined variables during the sleep event later rather than guessing which variable something was saved to.

If there is indeed a simple line of code that can help me with, I would really appreciate it!

Thanks again
Lui
Me again. As I am using Galv's event spawner there are no pre-defined plugin parameters for the event ID, it seems to just use whichever one is next free. It is then possible to check the ID of the last event with this script call:

$gameMap._lastSpawnEventId

So theoretically, each time an event is spawned, I can check its ID and save it to a variable. However, I then run into my next problem, as I don't know how to assign it to a different variable each time, and more importantly, how to check this variable with a different event later (during sleep) if I don't know what it is.

Ideally, I would predefine a set of variables (for example, 1-1000) and then automatically assign the ID value to whichever first one in that range is currently 0. This way, I can still check the pre-defined variables during the sleep event later rather than guessing which variable something was saved to.

If there is indeed a simple line of code that can help me with, I would really appreciate it!

Thanks again
Lui
Use notetags for the spawned events or push every $gameMap._lastSpawnEventId into an array. However, then you'll have to remove them from thr array every time you unspawn so notetags may be better.
@AquaEcho Thank you for the suggestion, however I am unfortunately not sure what you mean by using note tags at all. I have not worked with note tags on events before (only items and armor and so on). If there is some resource you can point me at to explain, or if you could go into more detail, that would be hugely appreciated. Thank you.
So theoretically, each time an event is spawned, I can check its ID and save it to a variable.
There's no reason to go through all that. Just say exactly what you're trying to do with your list, and ask for help with the code to do it.

As far as what @AquaEcho has been suggesting, you can put a notetag in your event templates and it should transfer to the spawned events. You could then, for example, get an array of all the events with the <plant> notetag with:
Code:
$gameMap.events().filter(currEvent => currEvent.event().meta.plant)

But then you'll have to manipulate that array for the things you want. So we need to know exactly what you are trying to do.
ATT_Turan beat me to it, but the event page will look like this
Alright, brilliant. I just watched a few tutorials about arrays in RPG maker and I am much clearer on things now. My coding knowledge is minimal and expands basically only when I try to learn new things for the RPG maker, and I didn't even really understand that arrays existed before this discussion. Thank you all for that alone!

Now for my setup. I hope this all makes sense but please question anything you need to.

Plugins used:
1. Galv's Event Spawner;
2. Yanfly's Self Switches/Self Variables.
3. Mjshi's Conditional Branch +

Events set up that should cross-reference each other:
1. Event "plant" on map 3 (the field) - x 1000
2. Event "sleep" (not on the same map as the field) - will likely become a common event

Maps: 3 (the spawn map, the field map, and the map with the bed/sleep event)

Variables and Switches:
  • Game variable Moisture (ID 34) - The water level to check if a plant can be watered. The mechanic is that the player (a water creature) waters plants by Event Touch and decreases Moisture by -1 each time.
  • Game variable Seedheld (ID 32) - The variable for the seed the player is holding (value assigned via the item select command)
  • Self Var Water (ID 783) - 0 is not watered, 1 is watered. (I found this easier than switches)
  • Self Var Plant (ID 785) - increases to show different plant sprites (ie 1 = tomato seed; 3 = tomato sprout; 5 = tomato plant; 6 = grape seed; and so on). This should increase by +1 every time the player sleeps IF self switch watered = on for this event. (The jumps between the values are so that a plant takes 2-3 "days" to grow to the next stage.)
Current setup (which I would love to streamline using your ideas if possible!)

Each square of the field is one event, all of which are identical as below, there will be about 1000 total of these (I may reduce this number if it proves too much for the game to handle)
  1. Page: Blank square, action button, below player. If the player presses OK while equipped with the hoe: Self Switch A = on.
  2. Page: Condition: Self Switch A = on. Tilled earth sprite, action button, below player. If the player presses OK while equipped with a seed: Self Var Plant (785) = n (depending on the seed).
  3. Page: Seed/sprout/whatever. Condition: Self Var Plant (785) = n (depending on seed and growth stage). Player touch, below player. If the player touches this: Self Variable Watered (783) = 1; Variable Moisture (34) -1.
Sleep Event:
For the sleep event, I currently do the following:
  1. Set Var 783 = this.getSelfVariableValue(3, 13, 783) # this sets it to variable 783 of event 13 on map 3, aka the Water variable
  2. If Var 783 = 1 (plant is watered), set this self variable to 0 using the plugin command: SelfVariable Map 3, Event 13, Variable 783 to 0, and proceed as follows:
  3. Set Var 785 = this.getSelfVariableValue(3, 13, 785) # this sets it to variable 785 of event 13 on map 3, aka the plant variable
  4. Use Conditional Branch + script call to check that the plant variable 785 is not 0, 6, or 12 (for no seed/grown plants): Check.is_not(785, 0,6,12)
  5. If this is the case, add +1 to the plant variable using the plugin command: SelfVariable Map 3, Event 13, Variable 785 to value + 1
This is quite simplified to spare you all the full details but basically, I then repeat the above 5 steps for every single event on Map 3 (event 14 ... 1013) to add +1 growth stage to every plant that has indeed been planted and watered.

Screenshots:
Event Setup Old.png

Spawn Setup:
If I understand you all correctly, I should instead use a parallel process to check if player is on a specific region ID (for example, RegionID 4) and if yes, and the OK button is pressed, and the player has a hoe equipped, then I spawn the event from the spawn map here instead.

The spawn event is identical to the one above, except that the first page doesn't exist and therefore no self switch A is required, and the note tag could say <plant> if relevant.

I got as far as this:

Spawn Event Setup.PNG

So ideally I now need a way to save the Event ID of the spawned event(s) in a way that I can then access with the above Sleep event... or an alternative if that is too complex.

Also, the above parallel event ironically causes a bit of lag - I experimented with adding Wait:10 or similar but that didn't help.

Thanks again, questions let me know
Lui
1. Event "plant" on map 3 (the field) - x 1000
Since you already have a parallel event checking for OK being pressed in the region, what purpose do the 1000 events serve? Unless you do mean one event per plant that gets copied up to 1000 times.
ie 1 = tomato seed; 3 = tomato sprout; 5 = tomato plant; 6 = grape seed; and so on
Any particular reason why you're using a single variable for both growth stage and plant type? Seems like it would be a lot easier to have that as two variables - it would make checking if a plant is ready for harvest easier, and much easier to make changes while developing the game, e.g. to remove/add new plants to the game, extend the growth time of an existing plant etc.

Each square of the field is one event, all of which are identical as below, there will be about 1000 total of these (I may reduce this number if it proves too much for the game to handle)
I'm assuming this will later also have code for harvesting? Other than that it looks reasonable.

This is quite simplified to spare you all the full details but basically, I then repeat the above 5 steps for every single event on Map 3 (event 14 ... 1013) to add +1 growth stage to every plant that has indeed been planted and watered.
That look good to me. If it ends up being a bit slow, you can always post on the forums asking for turning it into JavaScript code - turning an already working event to JavaScript should be rather simple.

Check if a plant is there already - HOW?
If script: $gameMap.eventIdXy($gamePlayer.x,$gamePlayer.y) > 0 - assuming there are no other events in the region

Also, the above parallel event ironically causes a bit of lag - I experimented with adding Wait:10 or similar but that didn't help.
That's because you need to have a wait command happen every time - not only when OK is pressed.
Since you already have a parallel event checking for OK being pressed in the region, what purpose do the 1000 events serve? Unless you do mean one event per plant that gets copied up to 1000 times.
I possibly didn't explain this very well: This is the current setup WITHOUT the event spawner being active. So instead of the event spawner, I just copy pasted this plant event onto every single space of my "field" map. Once completed, there would be 1000 copies of this event.

I am hoping to replace this method with the parallel event but I have not done so satisfactorily yet.

Any particular reason why you're using a single variable for both growth stage and plant type? Seems like it would be a lot easier to have that as two variables - it would make checking if a plant is ready for harvest easier, and much easier to make changes while developing the game, e.g. to remove/add new plants to the game, extend the growth time of an existing plant etc.
I experimented with a few different forms of this. I liked having one variable per plant type, for example, but that was very cumbersome to check them all during the sleep event. Although I did not think of the option you proposed (Var1 = plant type, Var2 = growth stage) - that would make a few things much easier. Thank you for that! Another example of me overcomplicating things a bit. 🙂

I'm assuming this will later also have code for harvesting? Other than that it looks reasonable.
Yeah, at the moment this is very simply "Add Vegetable +1 and set plant variable to 0" which seems to work fine.

If script: $gameMap.eventIdXy($gamePlayer.x,$gamePlayer.y) > 0 - assuming there are no other events in the region
Thank you!!!

That's because you need to have a wait command happen every time - not only when OK is pressed.
Thank you! I moved the Wait event to the very bottom of the event page and it works better now. I am still experiencing some lag - but that may be due to other factors. I will retry this in a clean install shortly to see if I have been clogging up things elsewhere.

Sadly this doesn't help me figure out how to check for the event IDs in the sleep event if I use the spawner - if anyone has any ideas in that regard I would appreciate it.

Original thread: https://forums.rpgmakerweb.com/threads/rmmv-your-experiences-with-lag.161149/