C
CodeD
Guest
SOLVED!
Hello,
I've been progressing through the Space Rocks tutorial in order to familiarize myself with inherent GameMaker functions.
For those who may be unfamiliar with this tutorial game: The base game is about just creating a spaceship which tries to shoot and dodge asteroids while trying to rack up 1000 points to win. There is another set of videos after the primary tutorial which enhances the base game with factions, enemies, parallax, powerups, etc...
My Issue:
Moving on, the game worked as intended when I completed the basic tutorials. However, when I moved onto the follow-up tutorials and added in factions the respawn code that I had set up in a persistent game object no longer works. If the player is hit by an asteroid, they are destroyed but the room does not restart after a small delay as intended (it doesn't restart period to clarify).
I am unsure about what happened because I haven't changed anything that the tutorial did not as well [aside from minor variations to scripts to match 2.3 format changes].
What I have tried:
- Combing through the forums to find this issue or similar issues like a good noodle : )
No exact results, closest was an issue with the base-game respawn that I already solved
- Checking to make sure there is only one player in the room
There is only 1
- Checking to make sure that the game object (with the respawn code is in the room)
I have the game object set to persistent, so yes it is
- Making sure, to the best of my knowledge, that everything is executed in the correct order
I'm pretty sure it is, but maybe there's something I don't see
- Moving the room_restart(); code to the ship object's destroy event instead of the game object's switch statement
Almost solved it, but the delay that I need (to make sure the debris has time to display) gets bypassed, restarting the room instantaneously.
I tried using an alarm here after instance_destroy(), set it to the room speed, then put the room_restart() code into the alarm event
However, I'd rather keep this code in the game object if I can just because it isn't getting destroyed like the ship
I feel like I'm running around in circles here so any help would be greatly appreciated!
The Code:
Here are what I believe to be the relevant blocks of code [Gamemaker Version 2.3.1.542 - Written in GML]
**This is the step event for an object titled "obj_game", which is present in all rooms. Note the last few lines of code which deal with the respawn \/
**This is the what is in Alarm[2] event of obj_game \/
**This is a collision event regarding obj_faction for obj_ship \/
**Finally, this is the user event called "Take Damage" of the ship which destroys it. \/
Once again, any help would be much appreciated! Also, if anyone has suggestions on post formatting feel free to let me know because this is my first post on the site.
Hello,
I've been progressing through the Space Rocks tutorial in order to familiarize myself with inherent GameMaker functions.
For those who may be unfamiliar with this tutorial game: The base game is about just creating a spaceship which tries to shoot and dodge asteroids while trying to rack up 1000 points to win. There is another set of videos after the primary tutorial which enhances the base game with factions, enemies, parallax, powerups, etc...
My Issue:
Moving on, the game worked as intended when I completed the basic tutorials. However, when I moved onto the follow-up tutorials and added in factions the respawn code that I had set up in a persistent game object no longer works. If the player is hit by an asteroid, they are destroyed but the room does not restart after a small delay as intended (it doesn't restart period to clarify).
I am unsure about what happened because I haven't changed anything that the tutorial did not as well [aside from minor variations to scripts to match 2.3 format changes].
What I have tried:
- Combing through the forums to find this issue or similar issues like a good noodle : )
No exact results, closest was an issue with the base-game respawn that I already solved
- Checking to make sure there is only one player in the room
There is only 1
- Checking to make sure that the game object (with the respawn code is in the room)
I have the game object set to persistent, so yes it is
- Making sure, to the best of my knowledge, that everything is executed in the correct order
I'm pretty sure it is, but maybe there's something I don't see
- Moving the room_restart(); code to the ship object's destroy event instead of the game object's switch statement
Almost solved it, but the delay that I need (to make sure the debris has time to display) gets bypassed, restarting the room instantaneously.
I tried using an alarm here after instance_destroy(), set it to the room speed, then put the room_restart() code into the alarm event
However, I'd rather keep this code in the game object if I can just because it isn't getting destroyed like the ship
I feel like I'm running around in circles here so any help would be greatly appreciated!
The Code:
Here are what I believe to be the relevant blocks of code [Gamemaker Version 2.3.1.542 - Written in GML]
**This is the step event for an object titled "obj_game", which is present in all rooms. Note the last few lines of code which deal with the respawn \/
GML:
if(keyboard_check_pressed(vk_enter)){
switch(room){
case rm_start:
room_goto(rm_game);
break;
case rm_win:
case rm_gameover:
game_restart();
break;
}
}
if(room == rm_game){
if(score>=1000){
audio_stop_sound(msc_space_rocks_theme)
room_goto(rm_win);
audio_stop_sound(msc_space_rocks_theme)
audio_play_sound(msc_win,1,false);
}
if(lives <= 0){
audio_stop_sound(msc_space_rocks_theme)
room_goto(rm_gameover);
audio_play_sound(msc_loss,1,false);
}
if((!object_exists(obj_ship))and(lives>0)){
alarm[2] = 3;
}
}
GML:
room_restart();
GML:
//Check if obj is a member of our faction
if(other.faction == faction) exit;
event_perform(ev_other,ev_user1);
GML:
/// @description Take Damage
instance_destroy();
audio_play_sound(msc_explosion,1,false);
repeat(10){
instance_create_layer(x,y,"Instances",obj_debris);
}
lives = lives - 1;
Once again, any help would be much appreciated! Also, if anyone has suggestions on post formatting feel free to let me know because this is my first post on the site.
Last edited by a moderator: