how to restart a room?[solved]

Discussion in 'Programming' started by Lerchprinz, Mar 17, 2019.

Tags:
  1. Lerchprinz

    Lerchprinz Member

    Joined:
    May 7, 2018
    Posts:
    36
    i know, a very stupid question... but how can i actually use the room_restart() function?

    this:
    if(life <1){
    room_restart();
    }

    is just freezing my game. if i change room_restart to game_restart it restarts the whole game, but i just want to repeat the current room when dying.
    if i use my TRANS.MODE.GOTO function, the game reloads the room, but my player object stays at the point where he died...

    any ideas?
     
  2. Crazy Star

    Crazy Star Member

    Joined:
    Nov 21, 2017
    Posts:
    76
    Maybe reset the life var.
     
    Andy likes this.
  3. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    990
    I assume your player object is persistent from what you are saying. Room restart won't effect persistent objects (unless you have code in their Room Start event, which is the only thing that will be run on room_restart()). The game freezes because you check to see if life is below 1 in your player object. It is, so the room restarts. The next step, you check to see if life is below 1 in your player object, since it is persistent and it will continue exactly as it was before when the room restarts, life is indeed below 1, so it restarts the room. Repeat ad infinitum. You could reset the life variable back to whatever the max is in the Room Create event of the player object.

    The player object is staying in the same place for the same reason. It's x and y values don't get reset on the room restarting because it is persistent. You could also use the Room Start event to position your position your player according to where they should be when the room starts.

    However, the usual advice is to not use object persistence precisely because of problems like this.
     
    Andy likes this.
  4. Lerchprinz

    Lerchprinz Member

    Joined:
    May 7, 2018
    Posts:
    36
    my player object is not persistent and the dying animation is at a different object that the player transforms to.
    I dont want to have lifes in my game anyways, because it is going to have a one touch death system like in meat boy. Even if i just make a room_restart(); at the colision, it is not restarting....
     
  5. VagrantWhaleGames

    VagrantWhaleGames Member

    Joined:
    Jul 10, 2018
    Posts:
    58
    is the object holding the life variable persistent? Like Crazy Star said, you might have to reset it back to something so the player isn't dying instantly and the game is infinitely restarting. Otherwise, i'd start by trying to find which object is causing the problem...Which if it happens on player death, already narrows it down.
     
  6. Lerchprinz

    Lerchprinz Member

    Joined:
    May 7, 2018
    Posts:
    36
    nothing is persistent. And even if i dont use the player_death object at all and try to make a room restart with my player object the room does not restart.... or at least my player object is not moving from his point of death...

    EDIT: i tried it with resetting the life variable and now the transition animation is happening, and my character respawnes. but he respawnes at the same poin he died.

    EDIT2: i added a y-=200 variable to a roomstart event. when i get hit by an enemy, my character actually gets up by 200. so this means the room restarts, it is just not affecting my player object.... but why?
     
    Last edited: Mar 17, 2019
  7. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,280
    Open the player object, click show info, and copy everything from there and paste it in here.
     
  8. Lerchprinz

    Lerchprinz Member

    Joined:
    May 7, 2018
    Posts:
    36
    where is "Show info" in an object?
     
  9. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,280
    Wait, what version are you using? If it's studio 2, I have to look at that again. LOL
     
  10. Lerchprinz

    Lerchprinz Member

    Joined:
    May 7, 2018
    Posts:
    36
    it is 2, but i was able to fix it, by reseting my x and y variables. thanks alot ;)
     
  11. Lerchprinz

    Lerchprinz Member

    Joined:
    May 7, 2018
    Posts:
    36
    ok, i am back again... this whole room restarting thing is causing some troubles... could you look again?^^
    was finally able to fix it by myself... thanks everyone!
     
    Last edited: Mar 19, 2019 at 7:37 PM
  12. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,280
    So which part are we having the issue with? The player not restarting in the right spot or the room crashing the game?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice