Jump to content


Photo

Game freezes when main character dies.


  • Please log in to reply
34 replies to this topic

#21 Boxcar

Boxcar

    GMC Member

  • New Member
  • 18 posts
  • Version:Unknown

Posted 28 March 2012 - 07:31 PM

I want them to respawn only when i die and not when i switch rooms if you understand.
  • 0

#22 fluidic ice

fluidic ice

    GMC Member

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

Posted 28 March 2012 - 07:39 PM

This will create the enemies in the room you died in, although you will have to specify their x and y positions and how many should spawn.
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;
    if room = yourroom
      {
      instance_create(200,300,obj_enemy);
      //..create more enemies here at their spawn locations in the first room.
      }
    room_restart();
}

And how many rooms do you have?

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

  • 0

#23 Boxcar

Boxcar

    GMC Member

  • New Member
  • 18 posts
  • Version:Unknown

Posted 28 March 2012 - 07:45 PM

Thanks, but if i do i it like that, how do i make the code and so on in the next room for example? A new control object?
I up to 2 rooms right now but there are a LOT more coming. :smile:

And sorry if im being stupid or something, i just started using GM
  • 0

#24 fluidic ice

fluidic ice

    GMC Member

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

Posted 28 March 2012 - 07:55 PM

You would check for the different rooms such as:

if room = room1
      {
      instance_create(200,300,obj_enemy);
      //..create more enemies here at their spawn locations in the first room.
      }
if room = room2
      {
      instance_create(200,300,obj_enemy);
      //..create more enemies here at their spawn locations in the first room.
      }
...

This way is fairly un-optimized and some coding genius might be able to find a different way to achieve the same effect.
  • 0

#25 Boxcar

Boxcar

    GMC Member

  • New Member
  • 18 posts
  • Version:Unknown

Posted 28 March 2012 - 08:23 PM

Thanks! :smile:
  • 0

#26 Canite

Canite

    Canigget

  • GMC Member
  • 1358 posts
  • Version:GM8

Posted 28 March 2012 - 08:42 PM

Instead of persistent rooms you could also do this by making a global ds_list with all the enemies and items in it, with a value of 0 or 1 to indicate whether or not they should respawn when entering the room, then reset all the values if you die so everything respawns. It would actually be fairly simple to implement but might be a little hard for a beginner to understand. Would also require gm pro.
  • 0

#27 Boxcar

Boxcar

    GMC Member

  • New Member
  • 18 posts
  • Version:Unknown

Posted 29 March 2012 - 03:28 PM

I have GM pro but i dont know what a ds_list is, do you think you could explain if you have the patience and time?
  • 0

#28 Boxcar

Boxcar

    GMC Member

  • New Member
  • 18 posts
  • Version:Unknown

Posted 29 March 2012 - 03:47 PM

Also now if i go to room2 and die there i just end up in an empty room1 at the end of the level.
  • 0

#29 Boxcar

Boxcar

    GMC Member

  • New Member
  • 18 posts
  • Version:Unknown

Posted 30 March 2012 - 11:21 AM

Bumping because i need help with this.
  • 0

#30 Boxcar

Boxcar

    GMC Member

  • New Member
  • 18 posts
  • Version:Unknown

Posted 31 March 2012 - 09:35 PM

Bumping again (inb4 bans and so on)
  • 0

#31 Desert Dog

Desert Dog

    GMC Member

  • Global Moderators
  • 6409 posts
  • Version:Unknown

Posted 31 March 2012 - 09:41 PM

4 posts in a row is a 'bit much', okay?

What are you bumping for? What do you want to happen when you die in room2? What's wrong with room_restart();?
  • 0

#32 Boxcar

Boxcar

    GMC Member

  • New Member
  • 18 posts
  • Version:Unknown

Posted 31 March 2012 - 10:06 PM

What do you recommend that i do then? Create a new topic to clog the forum up even further? Stop making games cause i cant get help? I mean ive already searched for it, but im sorry if im breaking any rules.

When i die in room2 i want to start at the beginning of room2, with the code i have now i respawn at the end of a cleared room1.
  • 0

#33 Desert Dog

Desert Dog

    GMC Member

  • Global Moderators
  • 6409 posts
  • Version:Unknown

Posted 31 March 2012 - 11:01 PM

So room_restart()?
  • 0

#34 Boxcar

Boxcar

    GMC Member

  • New Member
  • 18 posts
  • Version:Unknown

Posted 01 April 2012 - 12:31 PM

Like it says in the thread (i assume you read the thread because thats what you generally do before posting) i used the code:
if global.hp<1 room_restart()
but that caused the game to freeze and play the deathsound over and over when the character died. :confused:
  • 0

#35 Desert Dog

Desert Dog

    GMC Member

  • Global Moderators
  • 6409 posts
  • Version:Unknown

Posted 01 April 2012 - 06:51 PM

Like it says in the thread (i assume you read the thread because thats what you generally do before posting) i used the code:

if global.hp<1 room_restart()
but that caused the game to freeze and play the deathsound over and over when the character died. :confused:


I flicked through it. Frankly, I don't want to continue where the others left off, you sounded like you were getting a little confused.(and people were talking about ds_lists, of all things)

The reason the game freezes, and plays deathsound over&over is because global.hp is.. a global variable.

You restart the room.. but global.hp is still <1. So your code restarts it again. And again. And again..

So just set
global.hp=100 (or whatever your 'top health' is)
first, then room_restart()
if global.hp<1
{
   global.hp=100
   room_restart();
}

And for what it's worth, you're meant to have solved this problem already. Fluidic Ice gave you the answer..

Edited by Desert Dog, 01 April 2012 - 06:55 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users