Legacy GM [SOLVED] Using alarms as alternative create events

Greetings,

In specific circumstances, I've been using alarms as alternative create events.
The circumstances being that I require object A to create object B and object B must do some calculations in the create event with variables specified by object A. However, the create event for object B is run immediately before being given the chance to use the variables specified by object A. (that problem code below). So the solution is to put the calculations in an alarm in object B.

Code:
// OBJECT A create event
var b = instance_create(x, y, obj_b);
b.image_angle = 25;

// OBJECT B create event
if (image_angle == 25) do some calculations // this will never be 25 at the moment of creation
// so we must do alarm[0] = some value (say, 0.5), and put the above if statement in alarm 0. Problem solved.

My problem
Apparently, depending on the amount of stuff being processed (game wide?), the set alarm time, say 0.5 or whatever, can at times not be long enough for object B to "get" the values specified from object A before the alarm triggers. i.e. an alarm time of 1 works, but an alarm time of 0.6 or less does not.
 

Simon Gust

Member
You can precalculate the objectB create event by using a with statement
Code:
// OBJECT A create event
var angle = 25;
var b = instance_create(x, y, obj_b);
with (b)
{
    image_angle = angle;
    if (image_angle == 25)
    {

    }
}
 

Toque

Member
Greetings,

In specific circumstances, I've been using alarms as alternative create events.
The circumstances being that I require object A to create object B and object B must do some calculations in the create event with variables specified by object A. However, the create event for object B is run immediately before being given the chance to use the variables specified by object A. (that problem code below). So the solution is to put the calculations in an alarm in object B.

Code:
// OBJECT A create event
var b = instance_create(x, y, obj_b);
b.image_angle = 25;

// OBJECT B create event
if (image_angle == 25) do some calculations // this will never be 25 at the moment of creation
// so we must do alarm[0] = some value (say, 0.5), and put the above if statement in alarm 0. Problem solved.

My problem
Apparently, depending on the amount of stuff being processed (game wide?), the set alarm time, say 0.5 or whatever, can at times not be long enough for object B to "get" the values specified from object A before the alarm triggers. i.e. an alarm time of 1 works, but an alarm time of 0.6 or less does not.
Im assuming that you need at least 1 ish cycle to run for the code to run once. If you need things to fire in a sequence?
 
You can precalculate the objectB create event by using a with statement.
Yes, neat idea Simon! That could work, thanks. However in this case the calculations and other stuff I'm doing including the additional creation of more objects would, I think, be problematic. But that is a cool approach! I will remember it.
 
Im assuming that you need at least 1 ish cycle to run for the code to run once. If you need things to fire in a sequence?
Yes, a full cycle is probably necessary. I was worried that if there were "skipped frames" or some other anomaly, that even setting the alarm to room_speed could still result in stuff not getting processed.
 

Toque

Member
There's some good methods here! Thank you for referring them FrostyCat. A lot of the code I currently have in the alarm method has multiple 2d arrays and the thought of converting all these to global variables gives me the shivers. :confused:
Your avatar looks like my Vic 20 setup. Sweet.
 
Top