• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Space Rocks player not respawning

H

Hannah Tindal

Guest
I just followed the tutorial on space rocks and for the life of me I cannot figure out why my ship isn't respawning. I've tried every variation of resets in the collision event for the asteroid in my obj_ship events and it's not working.

Either it doesn't respond at all, or if I try to redraw it via an "instance_create_layer" (which I know wasn't what was said, I was just trying anything at this point) the game crashes.

I've also tried not using the alarm and instead trying:

if(obj_ship == instance_destroy()){
room_restart()
}

instance_destroy();

lives -= 1

repeat (10){
instance_create_layer(x,y, "Instances", obj_debris);
}


But, that doesnt work either.

I am absolutely losing my mind. It may be that I have been up all night doing this for a project and haven't slept yet but I am close to just absolutely weeping. Please help me.
 

Relic

Member
While I am unfamiliar with the space rocks tutorial, I can point out what is wrong with your attempt shown.

Code:
if(obj_ship == instance_destroy())
instance_destroy() is a function. A function may or may not return something back. Check the manual for instance_destroy() - you will see that it says Returns: N/A. So asking if obj_ship= instance_destroy won't be working as you hope.
What you should use is :

Code:
if(!instance_exists(obj_ship)
}
The manual entry for instance_exists() shows that it returns a boolean - a true or false value depending whether the argument (obj_ship here) exists in the room or not. Using '!' negates the value returned.

Restarting the room after that might be all you need - anything that is not persistent will be removed from the room and the room will be recreated like new.
 

samspade

Member
Adding to what Relic said. If your using the collision event in the ship to destroy the ship and it looks like this:

Code:
instance_destroy();

global.lives -= 1; 

repeat (10){
     instance_create_layer(x,y, "Instances", obj_debris);
}
Note the change to global.lives. If lives is an instance variable inside the ship, then when the ship is destroyed, it doesn't matter anymore. So you want to track lives outside of the ship itself. It could be global or it could be in some type of controller or manager object. Inside of whatever tracks the lives, I would put the code Relic posted and add the following:

Code:
if (!instance_exists(obj_ship)) {
    if (global.lives >= 0) {
        ///create a new ship however you've been trying to
    } else {
        game_restart(); //or whatever you're trying to do when there are no lives left.
    }
}
 
Top