• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Alarms not working?

T

telli01

Guest
Hello everyone,

I want to create a new instance of an enemy_obj at a random position with a delay of 2 seconds when it gets destroyed.
This is my code and the alarm does not work so far:

DESTROY EVENT
Code:
alarm[0] = 2*room_speed;
show_debug_message("enemy instance destroyed!");
ALARM 0 EVENT
Code:
show_debug_message("alarm activated");
instance_create_layer(irandom(1024),irandom(768),"PlayerEnemyLayer",enemy_obj);
 

FrostyCat

Redemption Seeker
Alarms only run when the instance having it set still exists. Given that your alarm is set in the Destroy event, the instance is guaranteed not to exist at the time the alarm is due to elapse.

Whenever you want code to be executed in the background independent of the current instance, you should create instances of proxy objects and let them take it from there. Here you can use a new invisible object as a proxy for creating enemy_obj:

enemy_proxy_obj Create:
Code:
alarm[0] = 2*room_speed;
enemy_proxy_obj Alarm 0:
Code:
instance_change(enemy_obj, true);
Then instead of setting the alarm that won't ever see the light of day, just create an instance of enemy_proxy_obj and leave it at that:
Code:
instance_create_layer(irandom(1024), irandom(768), "PlayerEnemyLayer", enemy_proxy_obj);
 
T

telli01

Guest
Alarms only run when the instance having it set still exists. Given that your alarm is set in the Destroy event, the instance is guaranteed not to exist at the time the alarm is due to elapse.

Whenever you want code to be executed in the background independent of the current instance, you should create instances of proxy objects and let them take it from there. Here you can use a new invisible object as a proxy for creating enemy_obj:

enemy_proxy_obj Create:
Code:
alarm[0] = 2*room_speed;
enemy_proxy_obj Alarm 0:
Code:
instance_change(enemy_obj, true);
Then instead of setting the alarm that won't ever see the light of day, just create an instance of enemy_proxy_obj and leave it at that:
Code:
instance_create_layer(irandom(1024), irandom(768), "PlayerEnemyLayer", enemy_proxy_obj);
Hello Frosty Cat,

Oh, OK! That makes perfect sense. I will try that. Thank you for your support! But I don't quite get, what the instance_change(enemy_obj,true) line does.
Is it in general a good practice to work with proxy_objects?
 
Top