peq42_

Yeet
Veteran
Joined
Feb 5, 2016
Messages
559
Reaction score
351
First Language
Portuguese(BR)
Primarily Uses
RMMV
I'm making a game using Yanfly's event spawner(http://www.yanfly.moe/wiki/Event_Spawner_(YEP)) in a project of mine. As one of the side game modes, I've been making a tower defense, and on it there's an event that can be built by the player which is a tower that shoots arrows. Those arrows get spawned, move 4 times on a given direction, then erased.

Issue is, over time, with more and more events being made, the performance starts to degrade, even tho most of them are erased and shouldn't be updated anymore(they create no setIntervals or anything of the sort). After trying to run some performance checks, I've found out that the tilemap(mainly its update function) seems to be taking over half of the run time of each frame draw

118.png


What could be going on? As far as I can tell, the events that get erased dont even contain a sprite anymore(I checked $gameMap to make sure), why is it that tilemap updates of all things is causing the lag issues, and how could I solve this?
 

Frostorm

[]D[][]V[][]D
Veteran
Joined
Feb 22, 2016
Messages
2,788
Reaction score
2,232
First Language
English
Primarily Uses
RMMV
Sry I can't be of much help, but I was curious what program you're using in that screenshot?
 

Frostorm

[]D[][]V[][]D
Veteran
Joined
Feb 22, 2016
Messages
2,788
Reaction score
2,232
First Language
English
Primarily Uses
RMMV
Ah, I'm such a nub lol...:kaoswt:
 

shockra

Bored Code Guy
Veteran
Joined
Feb 16, 2016
Messages
481
Reaction score
227
First Language
English
Primarily Uses
RMMZ
When the arrows are erased, are they erased or despawned? The erased arrows can still be in the map data even if it isn't currently there because depending on the settings, a spawned arrow that was erased can still reappear if you leave the map and come back. I would use the despawn command instead of erase to ensure that the event is truly gone.
 

peq42_

Yeet
Veteran
Joined
Feb 5, 2016
Messages
559
Reaction score
351
First Language
Portuguese(BR)
Primarily Uses
RMMV
When the arrows are erased, are they erased or despawned? The erased arrows can still be in the map data even if it isn't currently there because depending on the settings, a spawned arrow that was erased can still reappear if you leave the map and come back. I would use the despawn command instead of erase to ensure that the event is truly gone.
I tried it, but they still show in $gameMap._events
 

shockra

Bored Code Guy
Veteran
Joined
Feb 16, 2016
Messages
481
Reaction score
227
First Language
English
Primarily Uses
RMMZ
They show there, but do they keep appearing there after they're despawned? If so, there may be an error somewhere in the process. Can you post the event you used to create and despawn the arrows?
 

peq42_

Yeet
Veteran
Joined
Feb 5, 2016
Messages
559
Reaction score
351
First Language
Portuguese(BR)
Primarily Uses
RMMV
They show there, but do they keep appearing there after they're despawned? If so, there may be an error somewhere in the process. Can you post the event you used to create and despawn the arrows?
you see, the issue isn't whether or not they appear again upon map transfer, but that they keep being updated for each frame apparently, which causes exponential loss in FPS.
 

shockra

Bored Code Guy
Veteran
Joined
Feb 16, 2016
Messages
481
Reaction score
227
First Language
English
Primarily Uses
RMMZ
you see, the issue isn't whether or not they appear again upon map transfer, but that they keep being updated for each frame apparently, which causes exponential loss in FPS.
I get that, but I'm not sure the exact code is correct. If I can see the event for the arrow, it can be determined if the problem is there or elsewhere.
 

peq42_

Yeet
Veteran
Joined
Feb 5, 2016
Messages
559
Reaction score
351
First Language
Portuguese(BR)
Primarily Uses
RMMV
I get that, but I'm not sure the exact code is correct. If I can see the event for the arrow, it can be determined if the problem is there or elsewhere.
I removed everything from the event for a test. All it has right now is a script containing "Yanfly.DespawnEventID(this._eventId)" and an erase event command

Also, without spawning that many events, the game won't lose FPS over time.
 

shockra

Bored Code Guy
Veteran
Joined
Feb 16, 2016
Messages
481
Reaction score
227
First Language
English
Primarily Uses
RMMZ
Are you certain it's actually despawning? With the erase event still there, the despawn might not be triggering and it's actually erasing the event instead. this._eventId may not work because "this" may not be referring to the event. My recommendation is to remove the erase command and only despawn the event. If the rest of the code is unchanged and the spawned event remains, we'll at least know where the problem is.
 

peq42_

Yeet
Veteran
Joined
Feb 5, 2016
Messages
559
Reaction score
351
First Language
Portuguese(BR)
Primarily Uses
RMMV
Are you certain it's actually despawning? With the erase event still there, the despawn might not be triggering and it's actually erasing the event instead. this._eventId may not work because "this" may not be referring to the event. My recommendation is to remove the erase command and only despawn the event. If the rest of the code is unchanged and the spawned event remains, we'll at least know where the problem is.
I remove the erase, leaving just the despawn and its still the same. Event gets erased, still is listed in $gameMap and still appears to get updated even tho it shoudln't
 

shockra

Bored Code Guy
Veteran
Joined
Feb 16, 2016
Messages
481
Reaction score
227
First Language
English
Primarily Uses
RMMZ
I really can't figure this out. Can you please post the events you use to create these effects. Take screenshots of the event pages of the towers and the arrows (and anything else that might apply) and post those. There's probably something we're missing.
 

peq42_

Yeet
Veteran
Joined
Feb 5, 2016
Messages
559
Reaction score
351
First Language
Portuguese(BR)
Primarily Uses
RMMV
I really can't figure this out. Can you please post the events you use to create these effects. Take screenshots of the event pages of the towers and the arrows (and anything else that might apply) and post those. There's probably something we're missing.
https://i71.servimg.com/u/f71/15/27/47/75/119.png
https://i71.servimg.com/u/f71/15/27/47/75/213.png
https://i71.servimg.com/u/f71/15/27/47/75/312.png
there, arrows and the "tower"

the arrowscript function:
Code:
window.arrowscript=function (theeventid){
var events=$gameMap.eventsXy($gameMap._events[theeventid]._x, $gameMap._events[theeventid]._y)
var eventslength=events.length
if(eventslength>1){
while(eventslength--){
if(events[eventslength]._erased==false && events[eventslength]._characterName=="Monster"){
events[eventslength].HP-=34
eventslength=0
$gameMap.eraseEvent(theeventid)
}}}
};
 

shockra

Bored Code Guy
Veteran
Joined
Feb 16, 2016
Messages
481
Reaction score
227
First Language
English
Primarily Uses
RMMZ
The tower has a few scripts I'm not familiar with. Specifically, the setInterval code. What does that do exactly? Also, the spawn code is Yanfly.SpawnEventAt1, a script I didn't see in any of the plugin notes. Is that a custom modification?
 

peq42_

Yeet
Veteran
Joined
Feb 5, 2016
Messages
559
Reaction score
351
First Language
Portuguese(BR)
Primarily Uses
RMMV
The tower has a few scripts I'm not familiar with. Specifically, the setInterval code. What does that do exactly? Also, the spawn code is Yanfly.SpawnEventAt1, a script I didn't see in any of the plugin notes. Is that a custom modification?
setInterval is a basic javascript function. It makes a function within it run every X milliseconds(in this case, 1000, or 1 second).

as for the spawnevent thing, I needed to create a second spawning function, in order to maintain 3 different groups of events on the multiplayer part of my game:
1-1000: Map events, made before the game start
1000-2000: Events that represent players
2000-infinity: Temporary events for the most part, that get deleted upon match reset and whatnot

The function is basically a copy. And once I run the despawn function no errors are thrown in the chromium console and the event gets erased normally, thus I dont think it is the cause of any issue
 

dopan

Veteran
Veteran
Joined
Mar 27, 2020
Messages
1,299
Reaction score
692
First Language
German
Primarily Uses
RMMV
I am no JS pro,but the system always has to ask about data, even if stuff is inactive ingame, ..
(aslong the script data action chain is still aktive)
also it could be that other data chains which are connected to the spawned events increase that fps loss..
(i got no idea for what you are using that much events,but that sounds like a lot of events anyway)
Did you try to use galvs eventspawner instead?
(that one worked better for my own purposes)
Or is there any solution to archieve your goals by using less events?
(that might be the best solution)
 

peq42_

Yeet
Veteran
Joined
Feb 5, 2016
Messages
559
Reaction score
351
First Language
Portuguese(BR)
Primarily Uses
RMMV
I am no JS pro,but the system always has to ask about data, even if stuff is inactive ingame, ..
(aslong the script data action chain is still aktive)
also it could be that other data chains which are connected to the spawned events increase that fps loss..
(i got no idea for what you are using that much events,but that sounds like a lot of events anyway)
Did you try to use galvs eventspawner instead?
(that one worked better for my own purposes)
Or is there any solution to archieve your goals by using less events?
(that might be the best solution)
galv's eventspawner results in the same: lag when the event count reaches thousands. As for whether or not the number of events is necessary, things could be done in a different way, but it would make the whole system a whole lot more complex.

As for data being checked even for events erased, yes, thats exactly the cause of the performance issue: MV seems to be updating even erased events.
Does anyone know how to avoid that? Where could I add a check on whether or not a certain event is erased so, in case it is, the system will skip over it
 

shockra

Bored Code Guy
Veteran
Joined
Feb 16, 2016
Messages
481
Reaction score
227
First Language
English
Primarily Uses
RMMZ
It may be the arrowscript. I see 2 possible issues.

1. The arrows erase themselves when they hit a target, not despawn.

2. the while part of the code says to execute the code as long as (eventslength--). Unless I'm mistaken, there's no way to end the code because the while circumstance is never met. Even when erased (or despawned), that while command could keep triggering constantly.

If 2 is the issue, simply removing the while line could solve the problem. I don't think it's needed anyway because it's redundant.
 

peq42_

Yeet
Veteran
Joined
Feb 5, 2016
Messages
559
Reaction score
351
First Language
Portuguese(BR)
Primarily Uses
RMMV
It may be the arrowscript. I see 2 possible issues.

1. The arrows erase themselves when they hit a target, not despawn.

2. the while part of the code says to execute the code as long as (eventslength--). Unless I'm mistaken, there's no way to end the code because the while circumstance is never met. Even when erased (or despawned), that while command could keep triggering constantly.

If 2 is the issue, simply removing the while line could solve the problem. I don't think it's needed anyway because it's redundant.
1. I tested before without that script, same result
2.if the condition inside while reaches 0, it stops, because 0==false in javascript. Same thing happens on for loops. Its for maximum optimization(less condition checks, and in this case, also less object property accessing in memory).
 

Latest Threads

Latest Profile Posts

Trailer is almost done for the game i can't wait to show it to everyone
I've got good news and bad news. The good news is, there aren't any bad news to report. The bad news is, there aren't any good news to report.

Or as others say, yesterday was uneventful.


I am curious that can you "understand/get the point" about what does this place do generally?
(ARPG game)
If anyone knows any C# programmers, please send them my way.
Chilling at night in a tavern.
ChillingAtTavern.png

After 'multiple breakdowns', it's finally over. 10/10 will do this again.

Forum statistics

Threads
129,856
Messages
1,205,752
Members
171,034
Latest member
MrDummyAcc_dot
Top