• 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 Alarms don't work properly

L

lasoris7

Guest
So I was making a side-scroll shooter from Shaun Spalding's tutorials , I used an alarm[0] for automatic shooting when holding spacebar,it works but I wanted to implement a powerup that makes you shoot bullets like a cone for 15 seconds then return back to normal shooting, I used an alarm for that (alarm 1) and alarm[0] and alarm[1] either cancelled each other , did nothing , shot normally or didn't work at all. I tried many ways but which one do you suggest ?

obj_player
events
Keyboard > Space
execute code


if (alarm[0] = -1)
{
alarm[0] = 5
}



and alarm[0] event is
execute code

bullet1 = instance_create (x,y-32,obj_bullet);
bullet1.direction = 90;

I tried many ways for making the cone powerup (collision with obj_powercone ,step,create,if alarm0 is not set, etc etc...) but none of them worked, so what should I do? (I'm using the steam free version of gms 1.4)
 

samspade

Member
You haven't really posted enough code for people to diagnose the problem you are having. However, I think this is probably not the best way to work with the idea in general as you're conflating two things (time to shoot, and manner of shooting) into one thing. Here is a suggestion for setting it up in a different way:

Code:
///set alarm
if (alarm[0] == -1) {
    alarm[0] = fire_rate;
}

//alarm[0]
scr_shoot_bullet(bullet_type);

///scr_shoot_bullet(bullet_type)
var bullet = instance_create(x, y, argument0);
with (bullet) {
    //do stuff
}

///however you set your powerup
scr_set_bullet_type(obj_bullet_cone, 15 * room_speed);

///alarm[1]
scr_set_bullet_type(obj_bullet, -1);


///scr_set_bullet_type(bullet_type, length);
bullet_type = argument0;
alarm[1] = argument1;
//optional addition: scr_set_fire_rate(bullet_fire_rate_map[? bullet_type]} //create a ds_map that stores fire rates based on object


///scr_set_fire_rate(fire_rate)
fire_rate = argument0;
There's some additional variables you'd have to initialize and code to fill in, but this system would give you a lot more flexibility. You can easily set your bullets to be different things, you can set the duration as well. You could also easily have powerups that change the fire and so on.

If you want an answer to your original question (why alarms weren't working right) you'd have to post all of the relevant code.

Also, remember to use code tags and indent when posting code to the forums. It makes it easier to read and more likely that you will receive prompt help.
 
L

lasoris7

Guest
thank you, It helped a lot. This is my first post I'll be more careful when explaining my problems, Thanks!
 
Top