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!
GM Version : 1.3
Target Platform : All
Download : N/A
Links : N/A
Summary:
I ran out of alarms while working on my project, because of such, I decided to make a tutorial video that shows how to program your own alarm(s) and active them!
Ladies and Gentlemen, grab a drink, open your notepad, and get ready to program your own custom alarm!
Nice format and presentation, but the way you implemented your custom alarms has a very hard-code-y feel to it.
Alarms are arrays, so following that convention would be wise, as it improves the amount of code you have to write, makes everything easier, and if you're using the alarm[0..11] array often, you'll be right at home using custom alarms that function the same way.
Using switches over if, when possible, should be encouraged, not discouraged; It will not create more than ONE more line of code than using IF's, and it is faster than using IF's.
IMHO; Nice tutorial for a beginner/intermediate, but I can't say that I would recommend using this in a serious project.
This is all pseudo-code, but should function with little to no modification.
You don't need to do comlicated things at all. First of all, I don't think that people run out of available alarms so often. Even if they do, they are doing something that they shouldn't per se. ~~
A better and simple way to make custom alarms would be to use an array. Or simply variables to act as countdown timers. There is no need to hold your left ear with your right hand across the head if you can simply hold it with your left hand. ^^"
You don't need to do comlicated things at all. First of all, I don't think that people run out of available alarms so often. Even if they do, they are doing something that they shouldn't per se. ~~
A better and simple way to make custom alarms would be to use an array. Or simply variables to act as countdown timers. There is no need to hold your left ear with your right hand across the head if you can simply hold it with your left hand. ^^"
//Create
alarms[0] = -1;
//Step
for (var i = 0; i < array_length_1d(alarms); ++i) {
if (alarms > -1) {
--alarms[i];
}
if (alarms[0] == 0) {
switch (i) {
case 0:
// do stuff for alarm 0
break;
case 1:
// do stuff for alarm 1 here
break;
}
}
}
// Set alarm
alarms[0] = 60;
I never use arrays for my custom alarms. I think it hurts readability...I just use variables like jumpTimer, deathTimer, etc. Then I don't have to remember what alarms [7] is supposed to do...
I never use arrays for my custom alarms. I think it hurts readability...I just use variables like jumpTimer, deathTimer, etc. Then I don't have to remember what alarms [7] is supposed to do...
that's a good point. I am in the arrays category right now because it makes the coding smaller and easier. But I think the readability is worth manually typing out
if jumptimer > -1 jumptimer -= 1;
else jumptimer = -1;
Using switches over if, when possible, should be encouraged, not discouraged; It will not create more than ONE more line of code than using IF's, and it is faster than using IF's.
I do NOT think switch statements are a good idea over ifs for this. I used that at first but its not how alarms work and will cause problems. Multiple alarms and timers can go off on the same frame and should be completely independent from each other. Switch statements will only pick one alarm that goes off per frame resulting in other alarms failing and breaking your game. On the same token, no else ifs!
I rarely ever use this technique but it can be helpful if you are implementing an alarm on a parent object to which their subordinate objects use alarms[0...11]. If you do not wish to track which objects use a particular alarm or be forced to reserve an alarm for a singular purpose, then I definitely recommend the custom alarm method.
I use a custom alarm to handle the enemy flash event on my own game and found it quite convenient. I am glad the OP mentioned this just in case anyone wishes to experiment its application.