• 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!

Legacy GM Alarm[0] is not updating before step event

S

Shadowblitz16

Guest
can someone tell me what event alarms are supposed to update?
I thought it was the alarm events which come before the step event but it seems like my project is not doing that.

I have it set up so that after the projectile is spawned it updates it alarm[0] and then goes to the step event and spawns a tail projectile.

doing this should make it so that the projectile and its tail projectile's alarms are descending making them activate the next step that the one in front of them activates.

sadly this is not the case and the first tail projectile has the same value in its alarm as the front projectile making them always in the same spot
 

TheouAegis

Member
Do you have an Alarm Event for the correct alarm? In other words, if you set alarm[0], do you have an Alarm 0 Event with code and/or comments in it?

Are you setting the alarm anywhere other than the Create Event or the Alarm Event? If so, you need to make sure that code is only being executed once before the alarm counts down. An alarm will not count down if it gets reset before it reaches 0.

If anything, post the OBJECT INFO for the bullet and the tail.
 
S

Shadowblitz16

Guest
@TheouAegis

Yes I have the alarm[0] event and it is the correct alarm number

I'm also assigning it via instance id after creation so it should be working

Code:
Information about object: Projectile
Sprite:
Solid: false
Visible: true
Depth: -1
Persistent: false
Parent: Entity
Children:
Mask:
No Physics Object
Create Event:
execute code:

/// Init Projectile Variables

//////////////////////////////////////////////////////////////////////////////////////////////////////
// Config
//////////////////////////////////////////////////////////////////////////////////////////////////////

config  = ds_map_create();
hitbox  = ds_map_create();
physics = ds_map_create();

//////////////////////////////////////////////////////////////////////////////////////////////////////
// Variables
//////////////////////////////////////////////////////////////////////////////////////////////////////

// Creation Vars
json = -1;
sprite = -1;
flipped = 0;
tails = 0;

// Flag Vars
active = false;
update = false;
collision = false;

// Hitbox Vars
rectangle[0] = 0; rectangle[1] = 0; rectangle[2] = 15; rectangle[3] = 15;
damage = 0;
hits = 1;

// Physics Vars
angular = 0;
angular_wrap = 1;
angular_peak = 0;
angular_base = 0;
angular_value = 0;
angular_accel = 0;
angular_decel = 0;
angular_homing = 0;

velocity = 0;
velocity_wrap = 0;
velocity_peak = 0;
velocity_base = 0;
velocity_value = 0;
velocity_accel = 0;
velocity_decel = 0;
velocity_homing = 0;

amplitude = 0;
amplitude_wrap = 1;
amplitude_peak = 0;
amplitude_base = 0;
amplitude_value = 0;
amplitude_accel = 0;
amplitude_decel = 0;
amplitude_homing = 0;

oscillation = 0;
oscillation_x = x;
oscillation_y = y;
oscillation_wrap = 1;
oscillation_peak = 0;
oscillation_base = 0;
oscillation_value = 0;
oscillation_accel = 0;
oscillation_decel = 0;
oscillation_homing = 0;

//////////////////////////////////////////////////////////////////////////////////////////////////////
// Builin Variables
//////////////////////////////////////////////////////////////////////////////////////////////////////

sprite_index = -1;
visible = false;
alarm[0] = 1;



Alarm Event for alarm 0:
execute code:

///Call Projectile Active

// Reset position spawner objects position
if (spawner.object_index != Projectile)
{
   x = spawner.muzzle_x;
    y = spawner.muzzle_y;
}
else
{
    x = spawner.xstart;
    y = spawner.ystart;
}

// Set Builtin Vars
sprite_index = sprite;
visible = 1;

// Flags
collision = true;
active = true;

Step Event:
execute code:

/// Update Projectile

//////////////////////////////////////////////////////////////////////////////////////////////////////
// Tail
//////////////////////////////////////////////////////////////////////////////////////////////////////

if ((instance_exists(spawner)) && (spawner.object_index != Projectile))
if (tails > 0)
{
   scr_projectile_spawn(json, config[? "id"], depth, 90, xstart, ystart)
    tails --;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
// Movement
//////////////////////////////////////////////////////////////////////////////////////////////////////
if (update)
{


    //////////////////////////////////////////////////////////////////////////////////////////////////////
    // Wave Motion
    //////////////////////////////////////////////////////////////////////////////////////////////////////
 
    amplitude_value = clamp((amplitude_value + amplitude_accel) - amplitude_decel, amplitude_base, amplitude_peak);
    oscillation_value = clamp((oscillation_value + oscillation_accel) - oscillation_decel, oscillation_base, oscillation_peak);
 
    oscillation += degtorad(oscillation_value);
    var _shift = amplitude * sin(oscillation);
 
    oscillation_x += lengthdir_x(velocity, angular+90);
    oscillation_y += lengthdir_y(velocity, angular+90);
 
    x = oscillation_x + lengthdir_x(_shift, angular + 180);
    y = oscillation_y + lengthdir_y(_shift, angular + 180);
 
 
    //////////////////////////////////////////////////////////////////////////////////////////////////////
    // Linear Motion
    //////////////////////////////////////////////////////////////////////////////////////////////////////
 
    //x += lengthdir_x(velocity, angular + 90);
    //y += lengthdir_y(velocity, angular + 90);
    var test = 0;
}


Draw Event:
execute code:

///Draw Self

draw_self();
if (active == true && update != true) { update = !update; }

for (var _i=0; _i<instance_number(Projectile);_i++)
{
   var _inst = instance_find(Projectile, _i);
    draw_set_colour(c_red);
    draw_set_font(fnt_small);
    draw_text(0, 0 + (8 * _i), _inst.alarm[0]);
}

Edit: sorry I came off a bit rude I didn't mean to
 
Last edited by a moderator:
S

Shadowblitz16

Guest
@TheouAegis you there?

Edit: Yep I can almost guarantee that it is not updating the alarm[0] event before the step event
it executes in this order..
- Debug periodically spawns projectile
- Projectile vars are calculated in script
- Projectile create event runs
- Projectile vars are set via instance id in script
- Projectile should be updating alarm[0] here but does not
- Projectile step event runs
- Projectile draw event runs
 
Last edited by a moderator:

TheouAegis

Member
Step Event runs.
Projectile is created.
Projectile's Create event runs.
Projectile's Step event runs.
Step Event Ends.
Draw Event Begins.
Draw Event runs.
Draw Event Ends.
Step Event Begins.
Alarm counts down.
Alarm Event runs.
Step Event runs.
Projectile's Step event runs.


In other words, if the projectile is created after the Alarm events have run, then the alarm in the projectile will not count down until the next alarm event after it has been created.

Consider the following:
If you create the projectile in the Draw event, the alarm will run before the projectile's Step event. If the depth is too low, it probably will draw before the Alarm event is run.
If you create the projectile in the Room Start event, the alarm will run before the projectile's Step event.
If you create the projectile in the End Step event, the draw event will run before the alarm event and the alarm event will run before the Step event.
If you create the projectile in the Step Event, the projectile's Step event will run before the alarm event runs.
 
S

Shadowblitz16

Guest
hmm then the event order in the docs are wrong

anyways I fixed it by just handling timers manually
 
Top