Message Timer

SOliD

Member
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!");
}
 

Alexx

Member
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.
 
A

anomalous

Guest
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

Member
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.

If you have examples that would really help
 

SOliD

Member
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.
thanks for the reply :D when you have suggestions to better or shorten the code, feel free to show me pls ;)
 

Alexx

Member
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:

SOliD

Member
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!");

Thank you very much! really helped me out :)
 
Top