Infinite battle loop problem

Heya everyone,

I'm using wandering monsters in my game, using the method layed out by The Infamous Bon Bon.  They work perfectly fine most of the time but there is oneglitch that has been popping up again and again and I'm not sure what the root of the problem is.

I first noticed it happen when the player entered the map directly adjacent to a monster - a battle would start and once the player defeated the monster the victory fanfare would play and they would be awarded their experience etc - and then a second time, then again and again, about ten times maybe before exiting the battle.  Upon returning to the map, the monster would still be there and the same thing would happen all over again forever.

I later found that the same thing happened when a player saved, quit and loaded the game while next to a monster, and now I have found that if two monsters attack the player at the same time, the second one will trigger the glitch.

Basicly, the monster is a three page event.  Page one deals with chasing the player.  Touching the player triggers a self switch which activates page two: this deals with combat.  Winning or escaping triggers page three which takes the monster off the field.

Is this infinite battle loop a common problem with an simple solution?  I'm at a loss.  I can post some screenshots of the events if any clarification is needed.  I hope this isn't all too vague.

Thanks for any help.

 
Show us screenshots of all pages. Include the WHOLE event window.
Ok, here's the screenshots - I'll include the scripts from the conditional branches too.

Page 1

MonsterPage01.png

Scripts from top to bottom:

Spoiler
($game_map.events[@event_id].x - $game_player.x).abs <= 1 && ($game_map.events[@event_id].y - $game_player.y).abs <= 3 || ($game_map.events[@event_id].y - $game_player.y).abs <= 1 && ($game_map.events[@event_id].x - $game_player.x).abs <= 3
Spoiler
$game_map.events[@event_id].direction == 2 && $game_map.events[@event_id].y < $game_player.y || $game_map.events[@event_id].direction == 8 && $game_map.events[@event_id].y > $game_player.y || $game_map.events[@event_id].direction == 4 && $game_map.events[@event_id].x > $game_player.x ||  $game_map.events[@event_id].direction == 6 && $game_map.events[@event_id].x < $game_player.x
Spoiler
(($game_map.events[@event_id].x - $game_player.x).abs + ($game_map.events[@event_id].y - $game_player.y).abs) == 1
Spoiler
$game_map.events[@event_id].direction == 2 && $game_player.direction == 2 && $game_player.y > $game_map.events[@event_id].y || $game_map.events[@event_id].direction == 8 && $game_player.direction == 8 && $game_player.y < $game_map.events[@event_id].y || $game_map.events[@event_id].direction == 4 && $game_player.direction == 4 && $game_player.x < $game_map.events[@event_id].x || $game_map.events[@event_id].direction == 6 && $game_player.direction == 6 && $game_player.x > $game_map.events[@event_id].x
Spoiler
$game_map.events[@event_id].direction == 2 && $game_player.direction == 2 && $game_player.y < $game_map.events[@event_id].y || $game_map.events[@event_id].direction == 8 && $game_player.direction == 8 && $game_player.y > $game_map.events[@event_id].y || $game_map.events[@event_id].direction == 4 && $game_player.direction == 4 && $game_player.x > $game_map.events[@event_id].x || $game_map.events[@event_id].direction == 6 && $game_player.direction == 6 && $game_player.x < $game_map.events[@event_id].x
Spoiler
$game_map.events[@event_id].direction == 2 && $game_player.direction == 4 && $game_player.y > $game_map.events[@event_id].y || $game_map.events[@event_id].direction == 2 && $game_player.direction == 6 && $game_player.y > $game_map.events[@event_id].y ||  $game_map.events[@event_id].direction == 8 && $game_player.direction == 4 && $game_player.y < $game_map.events[@event_id].y || $game_map.events[@event_id].direction == 8 && $game_player.direction == 6 && $game_player.y < $game_map.events[@event_id].y || $game_map.events[@event_id].direction == 4 && $game_player.direction == 2 && $game_player.x < $game_map.events[@event_id].x || $game_map.events[@event_id].direction == 4 && $game_player.direction == 8 && $game_player.x < $game_map.events[@event_id].x || $game_map.events[@event_id].direction == 6 && $game_player.direction == 2 && $game_player.x > $game_map.events[@event_id].x || $game_map.events[@event_id].direction == 6 && $game_player.direction == 8 && $game_player.x > $game_map.events[@event_id].x
Spoiler
$game_player.direction == 2 && $game_map.events[@event_id].direction == 4 && $game_player.y < $game_map.events[@event_id].y || $game_player.direction == 2 && $game_map.events[@event_id].direction == 6 && $game_player.y < $game_map.events[@event_id].y || $game_player.direction == 8 && $game_map.events[@event_id].direction == 4 && $game_player.y > $game_map.events[@event_id].y || $game_player.direction == 8 && $game_map.events[@event_id].direction == 6 && $game_player.y > $game_map.events[@event_id].y || $game_player.direction == 4 && $game_map.events[@event_id].direction == 2 && $game_player.x > $game_map.events[@event_id].x || $game_player.direction == 4 && $game_map.events[@event_id].direction == 8 && $game_player.x > $game_map.events[@event_id].x || $game_player.direction == 6 && $game_map.events[@event_id].direction == 2 && $game_player.x < $game_map.events[@event_id].x || $game_player.direction == 6 && $game_map.events[@event_id].direction == 8 && $game_player.x < $game_map.events[@event_id].x
Spoiler
$game_map.events[@event_id].direction == 8 && $game_player.direction == 2 && $game_player.y < $game_map.events[@event_id].y || $game_map.events[@event_id].direction == 2 && $game_player.direction == 8 && $game_player.y > $game_map.events[@event_id].y || $game_map.events[@event_id].direction == 6 && $game_player.direction == 4 && $game_player.x > $game_map.events[@event_id].x || $game_map.events[@event_id].direction == 4 && $game_player.direction == 6 && $game_player.x < $game_map.events[@event_id].x
Page 2

MonsterPage02.png

(the middle block of this page is just repeats of the Transparent ON/OFF movement command)

Page 3

MonsterPage03.png
Timing on parallel processes can be tricky - try the following, it might help:

On the third page, add a "control switch A=OFF" at the very first line, just in case that the switch B=ON on the second page prevents the A=OFF that is set there.

Because if that is not turned off by the end of the third page, it will go to the second instead of the first and automatically start another battle.
Thanks for the advice.  Saddly it doesn't seem to have affected it, though.  🙁

I just counted up and it awards exp/plays the fanfare exactly ten times, if that means anything?
I was having trouble replicating the bug to try out your advice (because of course I was) but it made me realise something more specific about the problem.

if you appear on the map next to a monster who you've never encountered (and is therefore on page One of its event) then everything is fine - its if you exit a map while a monster was chasing you, and then enter the map again next to that monster that the bug happens.  similarly, if you save while a monster was chasing you, then quit and load, it happens - but not if you were next to an oblivious monster.
Hey again,

I've set up a test arena to replicate the problem, if anyone might find that useful

[Download link no longer available]

Getting the bug to happen is a little tricky - you have to let the monster rush at you and while it enters the tile next to you, before battle commences; hit escape, save and then quit to menu.  the brief moment when both the player and the monster have a balloon icon above their head has usually worked for me.  once you've saved and exited, load the save and battle will begin as normal - fight and kill the monster and you'll see the glitch take place.
Morg, please avoid double posting, as it is against the forum rules. You can review our forum rules here. Thank you.


Edit your last post instead of multi posting.


So the problem is that you're using self switches, which do not reset when you leave the map and return.


You really don't need multiple pages for all of that. Your second and third pages are both set to parallel process, so you COULD take their content and put on the first page so the whole thing will just run. So that you don't need to copy the content and paste it multiple times, make use of Labels and Jump To Labels, or conditions, to only process the content you've currently got on the second or the third page. That should solve the problem.
Sorry about the rule infringement, I'll bear that in mind in future.

I have compressed everything into a single page, replacing all the self switches with Label commands, but I seem to be doing something wrong - when I enter an area with one of these new monsters the screen turns black and the game jams up.  Here is the event as it now stands:

LabelMonster.png

From what I can see, Labels area a fairly simple concept and I don't know why they should be causing this to happen.  I'm probably missing something obvious.
From what I can see the first "jump to label😛art 1" right before part 2 is causing the event to recalculate the direction and not allowing it to get to the battle processing.
That was actually the intention; The Part1, Part2 and Part3 Labels are meant to serve the roll the different pages had before hand.
If the screen turns black and the game jams up, there's a different problem. What other events/scripts have you got going on?
It's currently in a test area with only two other events - one of them is a quick event door and the other is a parallel process that hasn't caused any problems before in other maps (it calls a common event, which in turn goes through a bunch of conditional branches to see if a variable has exceeded certain values).  When I remove the new monster event the jamming problem seems to vanish (and reappear in the map I moved it to).

If I start the player in a different map, it runs fine until I'm transferred to the map with the new monster.

-----------

Edit:

I just ran another test where I removed both those extra events from the map - still the same problem 🙁
But the jump to label😛art1 is causing a loop in the event which is probably causing the jamming.
Part1 is supposed to loop.  You'll see 'Jump to Label: Part2' commands within it to break the loop when needed.  If this is causing the jam anyway, what would you suggest instead?

---[edit]----

I have included a download where you can view the event for yourself if you wish.

Download

---[edit]----

RIGHT.  So, I got it working again without any jamming.  Damara was in fact correct about the Loop causing the problem..  I have everything working on the one event page without the use of any switches.  It now functions exactly how its predecessor did.

Unfortunately, it functions exactly like it's predecessor did, including the glitch.  There is one difference, though - it only repeats the fanfare/awards exp between 1 and 3 times, rather than 10.  The monster still remains on the map afterwards, though so the battle will continue forever.

Here's a screenshot of the new event page:

FixedLabelMonster.png

---[edit]--- I'm currently working on a way to skirt around the problem.  I have inserted $game_switches[249] = true onto the end of the battle termination and game loading scripts - switch249 will activate an event page in the monster, making it stop whatever it was doing for 60 ticks before turning the switch off and returning to normal behavior.  This prevents the the glitch from happening, but as it stands it also prevents any monsters from being removed from the field - switch249 interupts the normal death/escape part of page 1.  I'm having trouble getting around this part; does anyone have any suggestions?

To recap:  Battle termination/game loading flicks a switch - all monsters on the map pause regular activity for 60 ticks - all monsters resume from the beginning of page 1, including the one you just fought (missing out it's usual consequences for battle victory/escape.).

---[edit]---

Ok!  I have the solution.  Instead of setting the switch to true on load/battle termination, I set it to false.  Then I made a conditional branch in the monster so battle could only commence if the switch were on.  Then I placed a parallel process in the map that checks if the switch is off, then turns it on after 60 ticks.  Monsters live and die as they were intended and the glitch does not occur!
Do the battle rewards still cycle or is everything working now?
Everything appears to be working now - the 60 tick pause is enough to keep battle from starting over again, and this queue of battles seems to have been what was causing the rewards to mess up too.  God knows why.

So while I don't feel like I've gotten the problem at its heart, I have eliminated the chances of it happening.

Original thread: https://forums.rpgmakerweb.com/threads/infinite-battle-loop-problem.39245/