GMS 2.3+ game_restart but restarting on other room rather than the top room order one

y Acid

Member
So, I recently started using GameMaker Studio 2, and also programming on its language, so, to help me out, I looked up a tutorial on how to make a game, and found the GML GameMaker tutorial "Your first game", where you build a game called Space Rocks, and after 2-3 days "making" the game, I ended it, but I really wanted to add some extra cool stuff,
and so far it is being awesome, if it wasn't for a little thing i can't find anywhere...
I animated a little video of a rocket launching using piskel and had the ideia to put it in the start of my game, like the games that have a little animation before the start shows up,
an example would be Lego Marvel Super Heroes 2, and so I did it, it turned out pretty good I think, no problems in that, the way I did that, is that I've created a room called "rm_intro" and in that room there is the rocket animation and I did so it would show a text after, no problems, but the problems show after, when come back to the game and run onto some problems by changing the room order, I did fix everything, but with a little cost..
So, coming back a little, while I was making the game, in the tutorial, I programmed so everytime I die (lose 3 lives and reset from the GameOver screen), the game would just restart entirely (game_restart()), but doing that now, I have to see the animation again everytime I die, so I was wondering how can I make the "game_restart" code restart me directly in my start screen, after the animation, even if i need to change all the code, I really just want to make this work...
I will leave some prints about how it works so it gets more understandable.
 

Attachments

Roldy

Member
So for clarity:
  1. The first time the game starts you want it to start at rm_intro
  2. But after calling game_restart you want it to start at rm_start
Correct?

If so I would suggest looking at the manual for game_restart.

That page list how that function works. It list all the things that won't be affected by game_restart:
  • Global variables will not be re-initialised unless explicitly coded as such - for example, the built-in global variable score will not start at zero after a game restart if it has been modified in the game already.
  • The GPU state will not be changed (so if you have set the draw colour or alpha, for example, it will remain at the changed value).
  • The game speed will remain at whatever you set it in your game code (if you changed it this change will be perpetuated).
  • Any asset from the Asset Browser that has been changed at run time within the game - for example if you change the origin for a sprite resource or shift the position of a path resource - will not be reset.
  • Dynamic resources like buffers, surfaces, data-structures or imported sprites will also not be cleaned up or removed (although you may lose references to them, so take care when using this function to either use global references for the dynamic resource, or to clean them up before the function is called).
The first one, global variables will not be re-initialized, should be of interest to you. e.g. When rm_intro starts check for a global variable. If that variable is set then skip the intro. When leaving rm_intro set the global variable, so we know to skip it. So when game_restart is called rm_intro will be skipped.

See if that works.
 

y Acid

Member
So for clarity:
  1. The first time the game starts you want it to start at rm_intro
  2. But after calling game_restart you want it to start at rm_start
Correct?

If so I would suggest looking at the manual for game_restart.

That page list how that function works. It list all the things that won't be affected by game_restart:
  • Global variables will not be re-initialised unless explicitly coded as such - for example, the built-in global variable score will not start at zero after a game restart if it has been modified in the game already.
  • The GPU state will not be changed (so if you have set the draw colour or alpha, for example, it will remain at the changed value).
  • The game speed will remain at whatever you set it in your game code (if you changed it this change will be perpetuated).
  • Any asset from the Asset Browser that has been changed at run time within the game - for example if you change the origin for a sprite resource or shift the position of a path resource - will not be reset.
  • Dynamic resources like buffers, surfaces, data-structures or imported sprites will also not be cleaned up or removed (although you may lose references to them, so take care when using this function to either use global references for the dynamic resource, or to clean them up before the function is called).
The first one, global variables will not be re-initialized, should be of interest to you. e.g. When rm_intro starts check for a global variable. If that variable is set then skip the intro. When leaving rm_intro set the global variable, so we know to skip it. So when game_restart is called rm_intro will be skipped.

See if that works.
Yes, that is correct, and the informations about the game_restart function is reeeally helpfull, didn't thought about looking at it.

So, I loved the idea of getting the global variable set after the intro so it skips it, but, I know how to set the global variable, but how do I do it so if it is >0 or true or whatever that is set so the variable gets working, so the next time I use game_restart it will skip the intro room?

Thanks a lot for the help btw, I appreciate it a lot.
 

woods

Member
if your..
rm_init holds your animation and goto rm_start
rm_start holds all of your initializing of things


instead of game_restart(); you can use room_goto(rm_start);
wouldnt that have basically the same effect?
if the rm_start is where you initialize things like setting global.score to zero etc...
 

y Acid

Member
if your..
rm_init holds your animation and goto rm_start
rm_start holds all of your initializing of things


instead of game_restart(); you can use room_goto(rm_start);
wouldnt that have basically the same effect?
if the rm_start is where you initialize things like setting global.score to zero etc...
I did looked up to use the room_goto, but, if I use room_goto and don't restart, my code that prevents enemies and asteroids from spawning on screen doesn't work, is there any way that I can make it work without needing to reset the game?
So basically, my game sets so everytime the ship loses HP, it destroys itself and restart the room, no problem in that, the problems with using room_goto, is that my event that starts the game room and prevents others spawning on screen, doesn't restart properly, as it is an Room Start event, without using the game restart it doesn't work as it should, and i've tried too some codes that could destroy the existing obj's and put another ones, but I can't make it work in any way...
If you can help me, it could be in any way, restarting the room ou deleting the existing obj, or maybe another way, thank you!
 

Attachments

woods

Member
after re-reading the OP, the basic want is to play the beginning animation once when you start the game...

maybe just a simple toggle when the animation is played would do the trick?


psudo-code
Code:
intro room control object or whatever you use to start the animation event
[code]
if (play_animation = true)
{
// play the animation;
play_animation = false;
goto rm_start;
}
now whenever you come back to this room when your game resets, the play_animation variable will be false ..not allowing it to play
 
Top