1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice
  2. NOTICE: We will be applying a Xenforo update on Tuesday 25th of February. This means that from approximately 10:00 to 14:00 BST the forums will be offline (or possibly longer). Sorry for the inconvenience! Official Announcement here.

GML alarm_set not working

Discussion in 'Programming' started by Unarthadox, Jan 15, 2020.

  1. Unarthadox

    Unarthadox Member

    Joined:
    Dec 28, 2019
    Posts:
    8
    when i try to set an alarm in the create event it doesn't do anything, my code: upload_2020-1-15_13-44-46.png upload_2020-1-15_13-45-0.png
     
  2. robproctor83

    robproctor83 Member

    Joined:
    Sep 30, 2019
    Posts:
    296
    Hmm, I have never tried using alarm_set, what does alarm[0] = 260 do? Are you certain room_restart isn't running, and it is just hitting a loop or something? Maybe try show_message(1); instead and see if that pops up anything.

    *edit - and a few things that could stop an alarm are things like destroying the object calling the alarm, or if you have another event setting/clearing the alarm without realizing it. For more debugging you can also run alarm_get(i) in something like the step event and see what the alarm is doing exactly.
     
  3. Unarthadox

    Unarthadox Member

    Joined:
    Dec 28, 2019
    Posts:
    8
    kinda new to gamemaker so i dont know what any of this means, but basically, alarm_set makes a timer for an alarm to go off, basically what i'm trying to do is make a certain number of seconds and then alarm 0 will do whatever is in it (for in this case, restart the room.)

    edit: something's probably looping the alarm since on certain times, lets say 50 will work but 75 will not.
     
  4. OblivionSkull21

    OblivionSkull21 Member

    Joined:
    Sep 26, 2017
    Posts:
    318
    What is your room_speed? Setting an alarm to go off after 260 steps with a room speed of 30 would mean it would take a little over 8 seconds for the alarm to go off. Perhaps you aren't waiting long enough to see the alarm reach 0??

    Steps to seconds are always calculated as # number of steps/ room_speed
     
  5. Unarthadox

    Unarthadox Member

    Joined:
    Dec 28, 2019
    Posts:
    8
    i've waited there for about 3 minutes, and i don't know how to check my room speed.
     
  6. OblivionSkull21

    OblivionSkull21 Member

    Joined:
    Sep 26, 2017
    Posts:
    318
    You set your room speed in the room editor. Also, if nothing in your room changes at all before that alarm ends (moving the player around, enemies moving around, etc.) then you won't notice a change because the restart is instantaneous.

    EDIT: If it still isn't working, try putting the alarm in a step event and check to make sure the alarm isn't already set before setting it:

    Code:
    if alarm[0] == -1{
    alarm_set(0,260);
    }
     
  7. Adjud

    Adjud Member

    Joined:
    Sep 11, 2017
    Posts:
    84
    just use:
    Code:
     alarm[0]=260;
     
  8. TailBit

    TailBit Member

    Joined:
    Oct 16, 2019
    Posts:
    142
    Is a instance of the object in the room?

    You can also tell it to draw the alarm value so you know when it should go off:

    draw event:
    Code:
    // so it still draw itself when draw event is active
    
    draw_self()
    
    draw_text(x+64,y, string(alarm[0]) )
     
  9. OblivionSkull21

    OblivionSkull21 Member

    Joined:
    Sep 26, 2017
    Posts:
    318
    alarm_set(0,260) and alarm[0]=260 are the exact same thing and will do the exact same thing. The problem will still persist regardless of which format the user is using
     
  10. robproctor83

    robproctor83 Member

    Joined:
    Sep 30, 2019
    Posts:
    296
    Here is an idea, make a totally new object and place it in your room. In the create event put

    alarm[0] = 260;

    and then in the alarm[0] event put this

    show_message("Success");

    Run the game, see if it puts up a message. If it produces an alert box then that likely means whatever object you are calling the alarm from is either being destroyed before the alarm triggers or you are accidentally clearing/resetting it without realizing. To debug that you need to put show_debug_message(get_alarm(0)); in the step event of whatever object you are trying to trigger that alarm on. Run the game and look at the output console (should be streaming a bunch of numbers) this should tell you what the alarm is currently set to. You need to see if it's going up and resetting, or if its being cleared, or what exactly.
     
  11. BaBiA Game Studio

    BaBiA Game Studio Member

    Joined:
    Jun 20, 2016
    Posts:
    927
    Can you show what code you have in your Animation End event? That's the only event you have not shown us, and if you happen to be destroying the instance in there then that may be happening before alarm has time to count down. That could also be why you have found that using 50 for you alarm works (as that might be just under 1 second if you have a room speed of 60) and the animation might take just slightly over that, but 75 on the alarm would be happening after the animation has ended and the instance has been destroyed.

    I'm just guessing, but if you could show that event code it might help.
     
  12. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,449
    It's a global game setting in GMS2.
     

Share This Page