GameMaker game freezes? [Solved]

B

Bladebss

Guest
hello, I have been getting this problem where when I run my game, it freezes and doesn't show me a bug report or anything I have to close the window my self and I'm non the wiser as to what has gone wrong?

it all started when I put an object spawner into the game, and the code in it is soo simple I just cant see how its causing a problem.

so I have boats that are going along paths I have defined for them to simulate trade routs, when the player collides with one, it ads the room and current coordinates to a global variable so that after the battle has finished the player returns to the room where they left off.
there is a spawner I made in the room that has no sprite its just an object with a creation code that sets the variable "duration" to 1600, then a step event that takes 1 from duration every step and at 0 duration it spawns another boat and resets "duration to 1600, and the boat has a creation code to start the trade route.

this spawner causes the game to freeze after I finish the battle, and should return to the previous room and x,y values as per the global variable.

this is the create event:
Code:
duration=1600;
this is the step event:
Code:
duration=duration-1;
if(duration<0){duration=1600 instance_create_layer(x,y,"Ins_char",obj_npc_boat1)};
I just don't get how this simple obj can be causing so much trouble!?

if I don't go into battle with the boat,, they spawn happy and fine and go along the trade rout and no freezing, only when I return to the room after battle?

I also have no clue how to work out what I have done wrong as the game just freezes and there's no output in the console.

if I remove this obj from the room all works just fine..? exept.. the boats don't respawn obviously

can any one point me in a direction to solve this?

I just did another quick test and this time is froze only after the battle had finished and I returned to the room and the second the boat spawns in it freezes? the inconsistency of it makes it even more confusing.. I wonder if the freezing on return is because the timer on the spawner has expired and another boat has spawned in so the game freezes before it get to the room? but if I finish the battle quickly enough I get to the room before another boat spawns and freezes the game?
 
Last edited by a moderator:

dapper

Member
Based on what I'm reading, you're creating one boat object every step. After a minute, you have 1600 boat objects. Is your game freezing due to too many objects?

Edit: never mind. I see that you're creating one boat every 1600 steps. I agree that an infinite loop sounds most likely.

If the game freezes when a new boat appears, I'd check the boat code.
 
Last edited:
B

Bladebss

Guest
It only freezes when the boat spawns, after i have finnished a battle. There are no for loops or whiles in the code for the boats, or the battle room or the spawner. I have some for loops in my menue in the battle room and in my inventory but no problems ocured with them as they have been in game for ages with no issue.
 
D

Danei

Guest
Do you have any persistent instances in the battle room which might be carrying back over into the other room?
 
B

Bladebss

Guest
The player object is persistant and goes to all rooms?
 
Could be caused by the semi-colon being positioned after the curly bracket. Maybe change it to this:
Code:
if (duration<0){
duration=1600;
instance_create_layer(x,y,"Ins_char",obj_npc_boat1);
}
 
D

Danei

Guest
Does the player instance have any loops in it? Every time I've seen an issue like this it was caused by an infinite loop.
 
B

Bladebss

Guest
yea it does, here is the 2 for loops it has, but they are not related to boats in any way they check for level up criteria in grids I have. they have been in game for months and are working for all I can tell?

Code:
{for(w=0; w< ds_grid_height(disp_inventory);w++){

if (ds_grid_get(disp_inventory,13,w) > ds_grid_get(disp_inventory,28,w)) {ds_grid_set(disp_inventory,19,w,true) ds_grid_set(disp_inventory,11,w,ds_grid_get(disp_inventory,11,w)+1)}
if (ds_grid_get(disp_inventory,19,w)=true){ds_grid_set (disp_inventory,14,w,ds_grid_get(disp_inventory,13,w) *2);
                ds_grid_set (disp_inventory,24,w,ds_grid_get(disp_inventory,24,w) + (ds_grid_get(disp_inventory,21,w)div 3));
       ds_grid_set (disp_inventory,25,w,ds_grid_get(disp_inventory,25,w) + (round(ds_grid_get(disp_inventory,22,w)/3)));
       ds_grid_set (disp_inventory,23,w,ds_grid_get(disp_inventory,23,w) + (irandom_range(1,5)));    
       ds_grid_set (disp_inventory,28,w,ds_grid_get(disp_inventory,14,w));
                   ds_grid_set(disp_inventory,19,w,false);
 }
}}
{for(e=0; e< ds_grid_height(wep_inventory);e++){

if (ds_grid_get(wep_inventory,13,e) > ds_grid_get(wep_inventory,28,e)) {ds_grid_set(wep_inventory,19,e,true) ds_grid_set(wep_inventory,11,e,ds_grid_get(wep_inventory,11,e)+1)}
if (ds_grid_get(wep_inventory,19,e)=true){ds_grid_set (wep_inventory,14,e,ds_grid_get(wep_inventory,13,e) *2);
                ds_grid_set (wep_inventory,24,e,ds_grid_get(wep_inventory,24,e) + (ds_grid_get(wep_inventory,21,e)div 3));
       ds_grid_set (wep_inventory,25,e,ds_grid_get(wep_inventory,25,e) + (round(ds_grid_get(wep_inventory,22,e)/3)));
       ds_grid_set (wep_inventory,23,e,ds_grid_get(wep_inventory,23,e) + (irandom_range(1,5)));    
       ds_grid_set (wep_inventory,28,e,ds_grid_get(wep_inventory,14,e));
                   ds_grid_set(wep_inventory,19,e,false);
 }
}}
 
B

Bladebss

Guest
Code:
if(boat_enemyhealth=0){
room_goto(roomlast)obj_player.x=poslastx obj_player.y=poslasty
 boat_enemyhealth =noone
 pause=false
 instance_destroy(attacker);}
this is the code I use to return to the room after battle

and below is how it is set up by the boat that spawns, so when the textbox is finished alarm[1] happens and this code runs and battle begins, poslasty,poslastx,roomlast,attacker and boat_enemyhealth are all global variables.

Code:
 if (alarm[1]) {poslasty = obj_player.y
             poslastx = obj_player.x
             roomlast = room
       attacker=obj_battleboat1
       boat_enemyhealth=100
       
       instance_destroy()}
 
 if (attacker= obj_battleboat1) {battle_sea()}
 
B

Bladebss

Guest
Ok so i just tryed removing the spawner and just placing 2 npc boats in the room and it freezes after battle then too. So it seems its got something to do with there being more than one of the same boat object in to room after battle or something?

I did wunder of the code for the global variables is causing some kind of loop?
 
D

Danei

Guest
Well... what is the code for the global variables? Also, you're not making a duplicate player instance when you return to the room, are you? That would be the case if the player instance is placed in that room in the editor. I'm not sure it would cause your issue, but would be undesirable either way.

Have you tried using the debugger for this at all? I'm not sure exactly where you should be putting your break points, but I would start poking around in the debugger at this point.
 
B

Bladebss

Guest
I found the problem!
It was an infinite loop, the attacker variable was not being reset at the end of a fight so when i was in an instance with the attacker i was looping forever in battle mode and end battle mode.

Thanx for the ideas guys, the infinate loop was correct it was just in an odd place lol
 
Top