Creating a countdown timer with Creation code?

Zapzel-24

Member
I have created a sentry enemy that fires at given intervals with the alarm variable however I feel like the alarms are too mechanical and mundane so I plan to set up an timer system as a creation code. I have a few ideas how to pull it off but the real trick is resetting the timer in the creation code to its original value to repeat the loop.

I plan to use the step event to call out the timer's value in the creation code and ticks down with every step there will be a if statement when the timer reaches zero it performs the firing and resets the timer again to repeat the process.

But the real question is can I really reset a value in a creation code and how can it be pulled off ?

*Note* the sentry I created is one object that uses a creation code value (index) to determine its appearance and the direction where its firing.
 
I think you misunderstand events. You can't make a one time event (like Create Event) loop. The only way to make it do anything like a loop is a for or while statement, but that will pause EVERYTHING else from executing until it completes. I have no idea what you mean by alarms being mechanical and mundane...Any timer is basically a variable counting down. You can use alarms, or you can create your own timer (using the Step Event, not the Create Event) with custom variables, but you can make the alarm system do anything that you could do in a custom system.

An example of a custom alarm system:

Create Event
Code:
custom_alarm = 60;
Step Event
Code:
if (custom_alarm > -1) {
  custom_alarm--;
}
if (custom_alarm == 0) {
  //Code you want executed when alarm triggers.
}
 

Zapzel-24

Member
I do not mean creation EVENT i meant creation CODE were you select an object in the room and a place custom code for the step event. As mentioned previously, I have a sentry that is one object that uses this method to determine where it should be facing and how its drawn. I was wondering if its possible to to make a timer creation code that resets itself, this is what I am talking about:

*Note* I am currently using the alarm variable as a temporary placeholder

//Alarm Event

Code:
// Aming Right
if (index == 1)
{
fire = instance_create(x,y,obj_bullet)
fire.speed = 5;
fire.direction = 0;
    
alarm[0] = 60;
}
//Aming Up
if (index == 2)
{
fire = instance_create(x,y,obj_bullet)
fire.speed = 5;
fire.direction = 90;
    
alarm[0] = 60;
}
// Aming Left
if(index == 3)
{
fire = instance_create(x,y,obj_bullet)
fire.speed = 5;
fire.direction = 180;
    
 alarm[0] = 60;
}
// Aming Down
if (index == 4)
{
fire = instance_create(x,y,obj_bullet)
fire.speed = 5;
fire.direction = 270;
    
alarm[0] = 60;
}
//Draw Event
Code:
//Facing Right
if (index == 1)
{
    draw_sprite(spr_sentry,0,x,y);
}

//Facing Up
if (index == 2)
{
    draw_sprite(spr_sentry_up,0,x,y);
}

//Facing Left
if(index == 3)
{
    draw_sprite(spr_sentry_left,0,x,y);
}

//Facing Down
if (index == 4)
{
    draw_sprite(spr_sentry_down,0,x,y);
}
And in the room I use the creation code and write the index number to determine each sentry object in the room were its facing and firing, But since this is one object they all of the sentries in the room share the same alarm system and fire at the same interval. I theorized that if its possible to create a timer system in the creation code it can create a level of unpredictability or make them firing in patterns that the player must anticipate.
 
Create Event:
Code:
if alarm[0] = -1{
alarm_set(0, room_speed * 10) //this is a ten second timer. Change it if you want for longer/shorter.
}

alarm[0] Event:

Code:
if alarm[0] = -1{
alarm_set(0, room_speed*10);
}
Then just put what you want to happen when the timer hits 0 inside the alarm event.

The create event doesn't reset the alarm. You reset the alarm INSIDE the alarm itself.
 
Top