Jump to content


Photo

Game freezes when main character dies.


  • Please log in to reply
34 replies to this topic

#1 Boxcar

Boxcar

    GMC Member

  • New Member
  • 18 posts
  • Version:Unknown

Posted 28 March 2012 - 04:37 PM

So im currently working on my first game which is a topdown shooter with some kind of sci-fi feel to it. Everything is running along pretty smoothly except for one thing: the game freezes and replays the death sound again and again and again when my character dies when its really just supposed to reset the room with the death sound played once. Im using a mix of DnD and coding if thats any help.
  • 0

#2 fluidic ice

fluidic ice

    GMC Member

  • GMC Member
  • 792 posts
  • Version:GM:Studio

Posted 28 March 2012 - 04:39 PM

Hey,
There's not much we can do if you don't post the code/D+D ;)
But did you check to see it's exiting any loops/reset any variables.
Also what GM version is this?
  • 0

#3 Boxcar

Boxcar

    GMC Member

  • New Member
  • 18 posts
  • Version:Unknown

Posted 28 March 2012 - 04:43 PM

Im using Game Maker 8.1 and as far as i can see theres no loops or resets. Also when the game freezes you have to spamclick the "X" button on the window of the game to be able to shut it down if it helps.

The code im using is the following in a step event of a "obj_control" object.
if global.ammo>100 global.ammo=100
if global.hp>200 global.hp=200
if global.hp<1 room_restart()
if global.hp<1 sound_play(uhoh)

  • 0

#4 fluidic ice

fluidic ice

    GMC Member

  • GMC Member
  • 792 posts
  • Version:GM:Studio

Posted 28 March 2012 - 04:46 PM

Hmm try this and see if it makes a difference:
if global.ammo > 100 global.ammo = 100;
if global.hp > 200 global.hp = 200;
if global.hp < 1 room_restart()
if global.hp < 1 sound_play(uhoh);
global.hp = 100;

Edited by fluidic ice, 28 March 2012 - 04:47 PM.

  • 0

#5 Boxcar

Boxcar

    GMC Member

  • New Member
  • 18 posts
  • Version:Unknown

Posted 28 March 2012 - 04:52 PM

It just made my character invincible unfortunately :confused:
  • 0

#6 fluidic ice

fluidic ice

    GMC Member

  • GMC Member
  • 792 posts
  • Version:GM:Studio

Posted 28 March 2012 - 04:55 PM

Oops, sorry lol forgot it was in step.

if global.ammo > 100 global.ammo = 100;
if global.hp > 200 global.hp = 200;
if global.hp <= 0 {sound_play(uhoh); global.hp = 100; room_restart();}

Edited by fluidic ice, 28 March 2012 - 04:56 PM.

  • 0

#7 Boxcar

Boxcar

    GMC Member

  • New Member
  • 18 posts
  • Version:Unknown

Posted 28 March 2012 - 04:59 PM

That makes him die and resurrect in the same spot he died in and not the beginning of the room. Any way to fix that?

Huge thanks for the help btw. :thumbsup:
  • 0

#8 fluidic ice

fluidic ice

    GMC Member

  • GMC Member
  • 792 posts
  • Version:GM:Studio

Posted 28 March 2012 - 05:04 PM

Huge thanks for the help btw.

Your welcome ;)

Err is this controller or room persistant by any chance?
If not:

if global.ammo > 100 global.ammo = 100;
if global.hp > 200 global.hp = 200;
if global.hp <= 0 {sound_play(uhoh); global.hp = 100; Obj_player.x = xstart; Obj_player.y = ystart; room_restart();}

Change the Obj_player to the object name of your player.

Edited by fluidic ice, 28 March 2012 - 05:08 PM.

  • 0

#9 Boxcar

Boxcar

    GMC Member

  • New Member
  • 18 posts
  • Version:Unknown

Posted 28 March 2012 - 05:08 PM

The room is persistant but i would like it to be that if its possible so that enemies stay dead when moving between rooms and such.
EDIT: just noticed that the controller is persistant, could this be whats causing the error?

Edited by Boxcar, 28 March 2012 - 05:09 PM.

  • 0

#10 fluidic ice

fluidic ice

    GMC Member

  • GMC Member
  • 792 posts
  • Version:GM:Studio

Posted 28 March 2012 - 05:09 PM

Edited last post, should solve the problem.
  • 0

#11 Boxcar

Boxcar

    GMC Member

  • New Member
  • 18 posts
  • Version:Unknown

Posted 28 March 2012 - 05:21 PM

When i tried your last piece of code all that happened was that he died and resurrected somewhere out of sight and all i could do was press the shoot button and hear the gunshot sound play.
  • 0

#12 fluidic ice

fluidic ice

    GMC Member

  • GMC Member
  • 792 posts
  • Version:GM:Studio

Posted 28 March 2012 - 05:30 PM

Okay i'll need more info, what position does the player start at? That code should respawn the player wherever they started on the map. Also are you using views, and if so are they updating after the player respawns?
  • 0

#13 Boxcar

Boxcar

    GMC Member

  • New Member
  • 18 posts
  • Version:Unknown

Posted 28 March 2012 - 05:43 PM

The player spawn at x:64 y:320 and im using views but even if i turn them off he just disappears.
  • 0

#14 fluidic ice

fluidic ice

    GMC Member

  • GMC Member
  • 792 posts
  • Version:GM:Studio

Posted 28 March 2012 - 05:49 PM

Are you able to re-paste what you have again with all the code and D+D in the controller?

Edited by fluidic ice, 28 March 2012 - 05:49 PM.

  • 0

#15 Canite

Canite

    Canigget

  • GMC Member
  • 1358 posts
  • Version:GM8

Posted 28 March 2012 - 06:13 PM

The problem with the code FluidicIce posted is that it is in a control object and you're setting the players position to the control objects xstart and ystart, instead of the players. Try changing it to:
if global.ammo > 100 
{
    global.ammo = 100;
}
if global.hp > 200 
{
    global.hp = 200;
}
if global.hp <= 0 
{
    sound_play(uhoh); 
    global.hp = 100; 
    Obj_player.x = Obj_player.xstart; 
    Obj_player.y = Obj_player.ystart;
    room_restart();
}
Also I added brackets and indents to clean the code up a bit.. :happy:
  • 1

#16 fluidic ice

fluidic ice

    GMC Member

  • GMC Member
  • 792 posts
  • Version:GM:Studio

Posted 28 March 2012 - 06:20 PM

Aw darn, should have noticed that. +1 :thumbsup:

Edited by fluidic ice, 28 March 2012 - 06:35 PM.

  • 0

#17 Boxcar

Boxcar

    GMC Member

  • New Member
  • 18 posts
  • Version:Unknown

Posted 28 March 2012 - 06:34 PM

That did it! Thanks a lot the both of you! :biggrin:
Is there any way i can make this work with persistent rooms? Because if i have persistent rooms now the enemies doesnt respawn.
  • 0

#18 fluidic ice

fluidic ice

    GMC Member

  • GMC Member
  • 792 posts
  • Version:GM:Studio

Posted 28 March 2012 - 06:45 PM

That did it! Thanks a lot the both of you! :biggrin:


:biggrin: Yw

Is there any way i can make this work with persistent rooms? Because if i have persistent rooms now the enemies doesnt respawn.

That sentence cancelled itself out?

Why do you need the room persistant what don't you want respawning when you come back?
  • 0

#19 Boxcar

Boxcar

    GMC Member

  • New Member
  • 18 posts
  • Version:Unknown

Posted 28 March 2012 - 06:53 PM

I want to be able to move between rooms without them changing back to their original state (ie medkits and ammokits respawning, enemies respawning etc.etc.)
I hope that clears it up :smile:
  • 0

#20 fluidic ice

fluidic ice

    GMC Member

  • GMC Member
  • 792 posts
  • Version:GM:Studio

Posted 28 March 2012 - 07:02 PM

Is there any way i can make this work with persistent rooms? Because if i have persistent rooms now the enemies doesnt respawn.

From this I gathered you want only the enemies to respawn every time the room is restarted?

I want to be able to move between rooms without them changing back to their original state (ie medkits and ammokits respawning, enemies respawning etc.etc.)

But there you said you don't want them to respawn. And the players respawning should work with the room persistant.

If you did want enemies to respawn each time the map is loaded:
You could use a controller in the room to create enemies in random spots around the room, or have them created in specific spots such as:
instance_create(200,300,obj_enemy);
instance_create(400,100,obj_enemy);

Edited by fluidic ice, 28 March 2012 - 07:09 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users