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

GameMaker Alarm help

L

Lance46

Guest
I am new to Game Maker and I am currently giving the Lite version a try before purchasing a full version. I apologize in advance if my naming is not conventional because I do not yet know the norms of naming sprites and objects and such. I also don't know how to make code look like code on my question(first post). I am having difficulty with an alarm. I am making a version of PAC MAN and anytime a power pellet is destroyed I activate the code to make my ghosts blue. This is in my power pellets code.
{
Parent_Ghost.sprite_index = Blue_Ghost
alarm[0] = 300 . //my room speed is 30. Should go off after 10 seconds
}

also in the power pellet code I have alarm 0 with the code as such
{
Blinky.sprite_index = Blinky
Pinky.sprite_index = Pinky
Inky.sprite_index = Inky
Clyde.sprite_index = Clyde
}
They ghosts never change back. Any help or advice would be greatly appreciated.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Okay, I would suggest that you use the "with" function, as the way you are doing it just now will only actually work for ONE instance of the ghost objects. When you use the point method "object.variable", it won't set all instances of that object, but instead, it'll just choose one of them. Also note that the alarm call is actually setting the alarm in the calling instance and not in the parent object, as the point method is only useful for one variable at a time. So, when you use "with" it will run the code for all and you can include the alarm call in it too. That means you should change your code to:

Code:
// PELLET EVENT
with (Parent_Ghost)
{
sprite_index = blue_ghost;
alarm[0] = 300;
}
I would also change the code to set the sprite index in the alarm too, and just check the object_index of the instance to see which sprite it should use with a "switch", like this:

Code:
// ALARM EVENT OF THE PARENT OBJECT
switch(object_index)
{
case Blinky: sprite_index = blinky_sprite; break;
case Pinky: sprite_index = pinky_sprite; break;
case Inky: sprite_index = inky_sprite; break;
case Clyde: sprite_index = clyde_sprite; break;
}
Note that in the alarm code it seems like you're using the same identifier name for both the object and sprite, so I'm not sure exactly what you should use there... Just check your names and alter the code above to suit.

You can find more information about these things from the following page in the manual:

https://docs2.yoyogames.com/index.h...ting/3_gml_overview/14_language_features.html

See the sections on "with" and "switch".

Hope that helps!

:)
 
L

Lance46

Guest
I just got around to trying out this code and it worked wonderfully. Thanks! My problem was I had my alarm in the wrong object. Switching it for the power pellet to the parent object fixed my problem.
 
Top