GMS 2 (SOLVED) Help with game freezing in RPG after battle?

T

TheTimmyBoy

Guest
Hello, I am making an RPG similar to the Mother series, and have run into a pretty big issue that I can't seem to figure out.

The game is isometric-overworld-based, and when an enemy in the overworld is run-into, you switch to a battle room resembling Mother, Dragonquest, etc. After winning the battle, the game is supposed to switch back to the overworld and have the objPlayer appear in the same location as he ran into the enemy, but with the enemy gone now, and everything else how it was before the fight.

Every time I complete a battle with enemy #1, the game correctly brings me back to the overworld in the correct location, however the game freezes, all other enemies previously on-screen are missing, music stops, and the game is frozen overall. The only thing still "moving" is other object idle animations, but I am unable to move my objPlayer and I have to close the current run. In another case with enemy #2, the same thing basically happens, but the enemies are back to their spawn points and move around normally, rather than not being there at all. In neither case does an error window appear, nor does anything show up in the compile/syntax error tabs.

I'm not sure what to put for what code I have, as I'm not sure what's causing this. I've checked a few things within the code for my player object, the enemy objects, and the battle codes, but nothing has changed with this issue when I alter code. I'm at a loss. I'm still sorta new at this and I don't really know how to use a debugger or if that could even help me. I do have the objPlayer set to persistent, as I'm not currently sure how to effectively move between rooms with multiple paths without this. No rooms are persistent.

If anyone is able to give a suggestion, it would be very much appreciated. If you need anything cleared up or want to see specific code please ask!
 
Last edited by a moderator:

Simon Gust

Member
Are you switching room between battle and overworld? Might be an issue with persistency.
Are you using deactivation functions? They can also screw with you.

Of course, you would have to show relevant code to receive further help other than that.
 

Relic

Member
The issue is way too vague to offer a solution. If stuck in an infinite loop you would not see any changes in animation so I figure it must be something about the room start event or perhaps create events of objects.

Is your overworld room persistent? Or are you "returning" to the overworld but moving the character to where he was before the battle? If the latter, the code showing how you handle returning to the overworld would be useful.

How are enemies added to your overworld? Are they placed in the room editor? Are they spawned by some control object? If the latter, the fact that they are not spawned upon your return suggests this code is never run. What happens as you go back to the overworld that might limit what code (enemy spawning and even music playing) could be prevented from occurring?
 
T

TheTimmyBoy

Guest
Are you switching room between battle and overworld? Might be an issue with persistency.
Are you using deactivation functions? They can also screw with you.

Of course, you would have to show relevant code to receive further help other than that.
I've edited the post a bit.
If by "deactivating functions" you mean what Yoyo calls "deactivating instances" in their manual, I am not. Not trying to nitpick I swear, I'm just new at this so want to make sure I understand!
 
T

TheTimmyBoy

Guest
The issue is way too vague to offer a solution. If stuck in an infinite loop you would not see any changes in animation so I figure it must be something about the room start event or perhaps create events of objects.

Is your overworld room persistent? Or are you "returning" to the overworld but moving the character to where he was before the battle? If the latter, the code showing how you handle returning to the overworld would be useful.

How are enemies added to your overworld? Are they placed in the room editor? Are they spawned by some control object? If the latter, the fact that they are not spawned upon your return suggests this code is never run. What happens as you go back to the overworld that might limit what code (enemy spawning and even music playing) could be prevented from occurring?
Here's my room start event for objPlayer:
Code:
/// @description  Move the player to saved position
if global.thex > 0 and global.they > 0 and room != rmGameOver {
    x = global.thex
    y = global.they
    direction = global.thedir
}

event_user(0)

///Event stuff

///Views

__view_set( e__VW.XView, 0, round(__view_get( e__VW.XView, 0 ) ))
__view_set( e__VW.YView, 0, round(__view_get( e__VW.YView, 0 ) ))

if !global.cutscene or get_flag(28) {
    __view_set( e__VW.XView, 0, min(max(x-__view_get( e__VW.WView, 0 )/2,0),room_width-__view_get( e__VW.WView, 0 ) ));
    __view_set( e__VW.YView, 0, min(max(y-__view_get( e__VW.HView, 0 )/2,0),room_height-__view_get( e__VW.HView, 0 ) ));
    __view_set( e__VW.XView, 0, round(__view_get( e__VW.XView, 0 ) ))
    __view_set( e__VW.YView, 0, round(__view_get( e__VW.YView, 0 ) ))
}
Should this be a room-end event you think?

I've edited the post a bit. No rooms are persistent, but objPlayer is.
Enemies currently are just placed manually in the editor. Later I plan on implementing spawner stuff, but I'm currently just trying to get the core stuff running.
 
T

TheTimmyBoy

Guest
Freeze most of the times happen with while() loops, so maybe that gives some ideas where to watch.
I only have two while loops in my entire code, and they have to do with dialog strings. Think this could really be what's happening? Battles are full of text, as they are menu-based. Take a look? Here's the only one that would be somewhat relevant, maybe:
Code:
//This is used to calculate line breaks before the text begins to type
//out, to prevent line breaks in the middle of a word.

if string_copy(str[message_display],1,position) != str[message_display]
{
   while(string_copy(str[message_display],1,position) != str[message_display])
   {
      position += 1 //Adds one to the position.
      //width_counter += string_width(string_char_at(str[message_display],position)) //Adds the width of the next character to the width counter

      if string_char_at(str[message_display],position) = " " //If the character at the position pst is a space...
      {
         last_space = position //Update the lst_spc variable to pst.
      }
    
      /*if string_char_at(str[message_display],position) = "#" //If the character at the position pst is a line break symbol...
      {
         width_counter = 0 //Restart the width counter. This is used in case you want to add manual line breaks.
      }

      if width_counter > global.line_len //If the width of the characters exceeds the number that's allowed in a line...
      {
         write_line(string(width_counter))
         write_line(string(global.line_len))
         width_counter = string_width(string_copy(display_string,last_space+1,string_length(display_string)-last_space+1)) //When creating a line break, make sure that the width of the extra letters that are being placed into the next row are being counted for.
         str[message_display] = string_copy(str[message_display],1,last_space)+"#   "+string_copy(str[message_display],last_space+1,string_length(str[message_display])-last_space) //Add a line break after the last space.
      }*/
   }
}
else
{
   display_position += 1 //Adds one to the position of the display string.
   display_string = string_copy(str[message_display],1,display_position) //Update the string that's being displayed.
}
 
You could test it yourself, put a show_debug_message("I'm in the While Loop!") and watch the output window to see if this gets output forever.

However, you said above that some idle animations are still playing. If you were really stuck in a while loop, nothing would be happening in game.

You might want to stick a break point in the code that takes you back to the over world, and step through your code line by line in debug mode, see if you can spot the problem.
 
T

TheTimmyBoy

Guest
Okay so I messed around with debug breakpoints and found my solution to be adding "objPlayer.canmove = true" to the destroy event of my parent enemy object code. Thanks everyone!
 
Top