Ace: Clear cache/ram by script call?

This is a little urgent so I don't really have time to look into the intricacies of this (probably best if someone with experience in this particular area handles this), but I think we're dealing with the RAM here.


Anyway, would it be possible to have a script activateable by script call that safely clears the entire cache/ram for the game? (And loads up the current map again if necessary)


I ask this because there is a segment of game where a lot of image files appear and thus enter the ram/cache, and from what I've seen and read, it isn't cleared out until the game is closed. Incidentally, before the game is closed, battles stop working and then when the game is reopened and reloaded, they work again. This leads me to believe there is a cacheing issue going on here. Like, new things cannot enter the cache because the cache is too full of old images or something like that.


(Basically, battles stop working until the game is saved and reloaded which is really odd)


Otherwise, a forced save and reload MIGHT work here if the above is too difficult.


Will take further suggestions.


Thanks!
Cache.clear is the command that will clear the cache.

$game_map.setup(map_id) is the command that will set up the map. But you probably don't want to use it, as it puts all the events back at their original positions, and any events that were erased will be recreated.

I'd be more inclined to look at what scripts you're using that might be adding to the issues, or in clearing the cache selectively - something like this (in a new script slot) should just remove all pictures from the cache:

module Cache def self.clear_pictures @cache.keys.select { |key| if key[0] =~ "Graphics/Pictures/" @cache[key].dispose delete @cache[key] end } endendand just call Cache.clear_pictures at the appropriate time.I haven't tested this - if you want to give it a go and you get errors, just post back with the error details.

tbh though - I'm not sure it sounds like a caching issue to me. That would mean you ran out of RAM on your computer - can you verify that with Task Manager? Are you using battle scripts other than the default?
CP battle system, but all battles work up until after this one map and nothing unusual happens for it save a lot of animations on the map. I will try to clear the cache - it will be fine, event-wise, as I can clear right at the end of the transition to a new map which occurs anyway.

Essentially, on-map touch battles simply stop working but I have nothing preventing this on the map or in any of the events. It seems to be quite a consistent issue, on anything not Win 7. What is strange is that it fixes itself upon a reload.

I cannot verify it on my end unfortunately as it appears other people are running into the issue, not me. Usually on Win 8 and 10, but I cannot narrow it down until I know what it is. Thus, the first thing to try was this cache clear. I will let you know if it works! Thanks!
If it has a lot of animations on the map, then you probably want to clear animations, not pictures.


By "on-map touch battles" do you mean when the battle is called via a Battle Processing command on an event?


It still doesn't sound like a cache thing. Is it only one particular map? Or any map, any battle?
There's a limit to how many animations you can play in a map in VXA unlike other older RM versions.

Each event can only play one animation at any one time and won't be able to play another until the 1st one has finished playing.

So unless you are playing a few animations at once on different events, the chance of animation lagging or even causing memory shortage is rare.

I don't think OS has anything to do with it either, since the scripts are internal. You mentioned RAM problem, so i am going to assumed your player is running into memory shortage crash and not lag. There might be a chance of memory leak in your game design causing that (because reloading a game will fix the problem).

Give Mithran's script a try to scan for any possible memory leak in the scripts you are using, then try removing those detected scripts with error and see if the problem continues.

http://forums.rpgmakerweb.com/index.php?/topic/17400-hidden-gameexe-crash-debugger-graphical-object-global-reference-ace/
Brill, thanks. Will try that too.

Shaz: all on touch battles simply stop working after this one intensive map.

What happens for the touch events is that you walk into a sphere, an animation plays and then you're whisked off into a battle. After battle, the sphere runs an animation and is destroyed. The battle simply never occurs, and the animation from the sphere gets stuck in a loop until reloading.

Will give the above leak finder a try as well.
The battle simply never occurs, and the animation from the sphere gets stuck in a loop until reloading.
That sounds like a collision bug from event touch method. The event is being triggered more than once and the animation keeps playing/starting.

Normally this only happen when you remove the "safety" of either event touch/animation playing. So you might want to check your custom scripts for those.

eg, having a custom script that modifies methods in Game_Events or having a custom script that modifies methods in Sprite_Base.

Try changing that to either player touch or button trigger and see if the problem is solved.
Unfortunately, this is really hard to test given that it only occurs under a very specific set of circumstances and fixes itself upon reloading, so I can't just "change to button press" and test it 🙁
No wait.. what version of RMVXA are you using?

The old 1.0 engine forgot to add a safety check on the player's trigger side.

Try add this snippet and see if it works, it's a fix from the SP1 package.

Code:
class Game_Player  alias vxace_sp1_start_map_event start_map_event  def start_map_event(x, y, triggers, normal)    return if $game_map.interpreter.running?    vxace_sp1_start_map_event(x, y, triggers, normal)  endend
No wait.. what version of RMVXA are you using?


The old 1.0 engine forgot to add a safety check on the player's trigger side.


Try add this snippet and see if it works, it's a fix from the SP1 package.
Autoupdates are on, Steam version.


1.02a
If that's the case, what's left to check is said in my previous post.

One of your custom script might have removed that "safety" check and caused the event or animation to trigger over and over again.

Did you tick the "wait till animation finish" check box? That might help too.

And you mentioned that it only happen after a particular map, so you might want to check for scripts that run only in that map too.

eg, custom weather script that modifies the Sprite_Base class.

Memory leak and that event start loop isn't related imo.. that "out of memory crash" only happen after the event's animation started to loop right? Or it can happen without triggering that event? Either way, it's still worth to give Mithran's script a try.

Mithran's debug script can help you identify a few of the buggy scripts that didn't dispose graphic properly causing overall lag/crash in a long run.
There's a limit to how many animations you can play in a map in VXA unlike other older RM versions.


Each event can only play one animation at any one time and won't be able to play another until the 1st one has finished playing.


So unless you are playing a few animations at once on different events, the chance of animation lagging or even causing memory shortage is rare.
I have quite a few animations set to play at a time. Essentially, the map is a "battle" map, and events wait (x) frames, then walk toward each other, then run an animation.


The only special script(s) I'm using in that map are to do with Galv's extra move route actions, eg go to (x,y).


However, I have this going, to run animations (with a different ID on the end):


@animation_id = 007


What I could try and do is change these to use Galv's setup instead (I can't remember where the specific syntax comes from, above) such as anim(7) but the script appears to simply turn what you put into that script call, into the long version above, anyway.


I put in the script you told me to, and I haven't seen a log from it yet. I will have to see if anyone else can send me their log if they run into the issue(s).
Can you show a screenshot of one of the events that has this issue? If there are multiple pages, show all pages. And include the whole event window, so we can see tabs, triggers, the lot.


Did you try my script (replacing Pictures with Animations) and see if it made a difference?
IThe only special script(s) I'm using in that map are to do with Galv's extra move route actions, eg go to (x,y).

However, I have this going, to run animations (with a different ID on the end):

@animation_id = 007
That might just be your problem.

Putting @animation_id = number in custom move_route isn't a good idea if you have the move route set to repeat. And there isn't a wait until animation finishes option there so it actually runs over and over again as the move route repeats, just that the default game engine doesn't allow a single event to play more than one animation at a time and it gets ignored(or was it queued? can't remember) until whatever animation that is currently being played finishes playing, then it will immediately play the next animation in line. You can easily set up an event to play animation using the event commands. So unless you have a good reason to, there's no such need to put that inside a move route.

If you need event to play animation the exact moment it collides with another event, you can consider trying this script too:

http://forums.rpgmakerweb.com/index.php?/topic/53173-event-triggers-event/

 

Playing multiple animations on the screen can cause lag in some slower machines. Especially the original animations in the database are meant for frontal battles that only play one animation at a time. The trick to reduce FPS lost/lag on it is to shrink the size of the animation you wish to play on the map screen to 50% or smaller. You can see the changes in performance dramatically.

Just happened to made a demo game with events fighting each other and a bunch of animations playing on the screen (even off-screen).

Re-wrote the animation method to enable single event plays multiple animations at the same time too. No lag or fps lost at all with the shrunken animations. But when using the original size, it actually freeze the screen for 0.01 second every time a long and large animation plays. Especially those hued/tinted.

 

When Mithran's script doesn't give you a log report, that means it detects no custom scripts causing memory leak/stacks/undisposed graphics.

A good sign indeed.
Can you show a screenshot of one of the events that has this issue? If there are multiple pages, show all pages. And include the whole event window, so we can see tabs, triggers, the lot.


Did you try my script (replacing Pictures with Animations) and see if it made a difference?
 
Am I alright to test with just Cache.clear to test if the issue is in the cache in general, first?

That might just be your problem.


Putting @animation_id = number in custom move_route isn't a good idea if you have the move route set to repeat. And there isn't a wait until animation finishes option there so it actually runs over and over again as the move route repeats, just that the default game engine doesn't allow a single event to play more than one animation at a time and it gets ignored(or was it queued? can't remember) until whatever animation that is currently being played finishes playing, then it will immediately play the next animation in line. You can easily set up an event to play animation using the event commands. So unless you have a good reason to, there's no such need to put that inside a move route.
Here is a setup example for the animation sources:


(Page 2 is just blank, switching it off - also covered up some minor spoilers)


d4UYOGn.png



1qx6Bun.png



Basically, once a battle is won elsewhere, this event will turn off.


The events in question continuiously approach and walk away from each other, play an animation and then walk back as if they are being struck or striking, etc.


Here are the combat enemies: (It is important to note the problem does not occur until the above animation sequence appears to run after playing the game for a while, so it isn't an issue to do with these events specifically. Also, the calling common event is to determine which set of enemies appears on the map. Obscured a spoiler. Enemies are removed with the "erase event" command to allow respawning.)

Spoiler
iPeo966.png



laU4OBV.png



PP5v1c7.png



8hWYZK0.png



GgTiI8p.png
The conditional branch, proxy check is provided by one of your custom script?

You have that on parallel process so it can run repeatedly over and over again.

 

Try change that condition check to:

$game_map.events[@event_id].x , $game_map.events[@event_id].y == $game_player.x , $game_player.y

If you need event x y to be the same as player x y

 

And if you are doing it using event touch, you don't really need to set up a parallel process for it. 

Simply set event to be "Below Character" and "Event Touch" should just do the trick without the above condition check.

 

If you need current event x y to be the same as, say, event 1 x y, use this:

$game_map.events[@event_id].x , $game_map.events[@event_id].y == $game_map.events[1].x , $game_map.events[1].y

 

Or you can simply use my event triggers event script.

http://forums.rpgmakerweb.com/index.php?/topic/53173-event-triggers-event/

It will not only detect collision with another event,

the event can actually trigger another event it came into collision with.

Making life a lot easier in settings. 😉
Unfortunately, I have too many of the same event set up around the game to be able to change it at this stage. Would fixing that actually lead to fixing this initial issue though? As far as I can see, it is simply a different way to activate the battle when the issue is that battles are not occurring (after the proximity check) in the first place. Yet, the battles occur just fine before this map (which is late in the game) and I had to set them up such so multiple ones didn't occur at the same time and cause issues etc.
The cause you are having there can be either having animation running in a repeating custom move route or having a parallel process running the animation.

Since you are trying to do a battle map with random NPCs fighting each other, the event triggers event script should do the job nicely imo. And seems like you want the events to chase the player in certain range too but seems awfully complex in the settings. You can try my chase script too and see if it works for your needs.

Like i said before, you can check to see how things work in the demo game i made using the Event triggers Event script.

http://forums.rpgmakerweb.com/index.php?/topic/53887-medic-medic/

It should give you a pretty good idea of how the script works. And instead of having to set up a move route, you can even let your events run freely around in a random move route. 😉 The example map to set up the events are provided in the script's tread.

[IMG]http://s23.postimg.org/5gp2px53v/Medic_Medic_SS_08.png[/IMG]
Just to clarify, the events fighting each other with animations are purely visual (except for when you press enter on them and initiate a battle and they self-switch A) while the on-map event touch ones are the ones that bug out AFTER the events fighting each other. The two events are totally different things.


EDIT: Actually, can we Skype? This might be easier if you can see my screen over Teamviewer, and the forum host has a bit of a DDOS attack at the moment. The answer will be posted here once solved, of course.
I don't think your bugs came after the event fights alone,

it's your parallel setting / trying to run animation in a repeated custom move route

that caused the accumulated bug.

Like i explained before, this type of bug will not happen

unless one of your scripts removed the "safety" of animation playing.

When you play animaiton in a parallel process, and the animation is queued,

it can actually que up to 60 sets of animation to run in a second.

And the animation will keep looping until all queued animations are played.

 

Can't 100% be sure of what custom script you have is causing that behaviour

since you didn't list the scripts you use in your top post, 

you will need to check your custom scripts for the main cause yourself.

 



 

The reason i recommended the E-E trigger script is:

The E-E Trigger script can do both simple visual and something deeper/more complex.

But it's much easier to use than the ones you are using right now imo.

 

It can let you have a few types of "trigger" based on "who" triggered the event.

 

So you can do something like:

When triggered by another event, play animation/do something.

When triggered by player, start a battle.

Or when triggered by event ID X, play another type of animation/self switch.

 

You only need to set up the condition branch on the trigger page if you want multiple trigger types.

And decide who is the triggering event and who is the trigger-able event with name tags.

The rest is just simple every-day eventing, nothing more, nothing less. It's that easy.

 

You can use any type of move route you like too, from custom to random.

As long as the triggering event touches the trigger-able event, it will trigger it and run the page.

 

If the triggering event touches a player, it will trigger itself.

 

And you can avoid the uses of parallel process/loop which lower your chance of bugging an event.

 

 

 

Well, it's up to you to choose what script to use. I can't give examples of scripts not made by me,

so all i can do here is give you an example of what to do if you are using the E-E trigger script:

 

Example:

 

All you need to do is separate the events in 2 groups

 

one group(bad guys?) with <eet> name tag and one group(good guys?) with <eer> name tag.

 

[1] On the <eer> event, simply have the setting set to trigger by button/player touch.

and set a repeating custom move route to move forward only. (one step forward and that's it)

In its command page, a simple play animation command (check wait till animation finish)

and a move route command to take one step back ward. that's all for it.

you can add conditional branch in its page so

it can be triggered by events only. (do nothing when player touches it)

Or set it up to start a battle when player touches it.

 

Since it seems to me you are good with script calls too, you can use something like this

to control the movement of the triggering event from the triggered event as well.

 

$game_map.events[$game_map.events[@event_id].triggered_by].move_backwardThis will move the event that triggered this event one step backward.

 

[2] On the <eet> event, set it to event touch trigger

and set custom move route as 1 step forward, 1 step back,

that's all for it. (if you use script call in the <eer> event to control move backward there,

then all you need here is move forward only)

Finally, in its command page, set it up to start a battle. so when the player touches it, a battle will start.

 

[3] Have one <eet> event and one <eer> event facing each other as sets.

 

That's all you need to do to make what you want happen without using any parallel processes at all.

 

I've attached a map sample to help you understand more.

Map001.rar

To use it, simply:

[1] Create a new game project

[2] Add the Event triggers Event script to the new project

[3] Save and exit.

[4] Then extract the rar file and replace the Map001.rvdata2 file in the data folder.

[5] Open the project and check how it's done. Give it a test play to see how it works too.

 

When you have both events made ready, the rest is as simple as copy and paste.

Original thread: https://forums.rpgmakerweb.com/threads/ace-clear-cache-ram-by-script-call.54113/