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
  2. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

Message Timer

Discussion in 'Programming' started by SOliD, Nov 13, 2016.

  1. SOliD

    SOliD Member

    Joined:
    Nov 13, 2016
    Posts:
    5
    Hello,
    i did code a message with the draw_text function but the message stays only for a second or less,
    so i want to show the message for more seconds after the condition is fulfilled even do the condition isnt true anymore. A delay string that stays on the Screen for a given time.

    pls help...

    Code:
    if (physics_test_overlap(x, y, 0, obj_Enemy))
    {
        draw_text(10, 20, "collision!");
    }
    
     
  2. Alexx

    Alexx Member

    Joined:
    Jun 21, 2016
    Posts:
    441
    There's a few ways to achieve this.
    You could have a flag set as true or false, and then use an alarm to show the message for the amount of time that the alarm is set for.

    Or you could just use a variable as a timer and display the message whilst it's counting down.

    If you need any code, just ask.
     
  3. anomalous

    anomalous Member

    Joined:
    Jun 29, 2016
    Posts:
    464
    Use an alarm/timer.
    Using alarms (I always use variable timers but that's not always best)

    in create:
    alarm0_max = 2*60; // duration in steps you want the text to be drawn, 2 seconds in this case at room speed 60

    step:
    if (physics_test_overlap(x, y, 0, obj_Enemy))
    {
    alarm[0] = alarm0_max; // sets the alarm to start counting down
    }

    draw event:
    if alarm[0] >= 0 draw_text(10, 20, "collision!"); // draws text if alarm is counting down

    The alarm stops at -1

    *Note this is what the post above suggests, although you can omit the flag if you use the timer value as the "flag". Up to you.
     
    SOliD likes this.
  4. SOliD

    SOliD Member

    Joined:
    Nov 13, 2016
    Posts:
    5

    If you have examples that would really help
     
  5. SOliD

    SOliD Member

    Joined:
    Nov 13, 2016
    Posts:
    5
    thanks for the reply :D when you have suggestions to better or shorten the code, feel free to show me pls ;)
     
  6. Alexx

    Alexx Member

    Joined:
    Jun 21, 2016
    Posts:
    441
    If you'd like the timer to start from when you the last collision occurs, use anomalous's example.

    If you'd like the timer to run from first colliding you can use:

    Create Event:
    Code:
     timer=-1;
    Step Event:
    Code:
    if your_collision_code && timer==-1
    {
       timer=60;
    }
    if timer!=-1
    {
        timer--;
    }
    Draw Event:
    Code:
    if timer!=-1 draw_text(10, 20, "collision!");
    Or using a flag and alarm:
    Create Event:
    Code:
    showing=false;
    Step Event:
    Code:
    if your_collision_code && !showing
    { 
        showing=true;
        alarm[0]=room_speed*2;
    }
    
    Alarm[0] Event:
    Code:
    showing=false;
    
    Draw Event:
    [code]if showing draw_text(10, 20, "collision!");
     
    Last edited: Nov 13, 2016
    SOliD likes this.
  7. SOliD

    SOliD Member

    Joined:
    Nov 13, 2016
    Posts:
    5

    Thank you very much! really helped me out :)
     

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