1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

[SOLVED]Need help with timer after player death

Discussion in 'Programming' started by jaigantor, Jun 4, 2019.

  1. jaigantor

    jaigantor Member

    Joined:
    May 22, 2019
    Posts:
    22
    hey so this might be a bit big (pulling code from a few objects) but I'm having an issue where the timer I have set to start after the player death doesn't work here's the code:

    in the object o_timer
    create:
    global.timer = 3;
    if instance_exists(o_player){
    alarm[0] = 0;
    }else{
    alarm[0] = 60;
    }

    in alarm 0:
    global.timer --;

    when an enemy collides with a player the play is destroyed and in the o_player destroy event is this code:
    if global.timer == 0{
    room_goto(Death);
    }

    i'm not sure why this won't work, any help appreciated.
     
  2. Nathan Laing

    Nathan Laing Member

    Joined:
    Jul 31, 2016
    Posts:
    355
    There are lots of ways to do this but here's one, based on what you seem to have in place:

    In the destroy event of the player, put:
    Code:
    o_timer.alarm[0] = 3 * room_speed; // start a 3 second alarm inside the o_timer object
    In the alarm 0 event of the o_timer object put:
    Code:
     room_goto(death); // go to the death room when this alarm triggers, which will be 3 seconds after player death 
    (You can get rid of all the global.timer code)
     
  3. jaigantor

    jaigantor Member

    Joined:
    May 22, 2019
    Posts:
    22
    Thank you so much, this works perfectly!
     
    Nathan Laing likes this.

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