Fangames > Programming Questions
Looping Actions?
BaronBlade:
Hello! I'm trying to recreate the cannon enemies from I Wanna Be the Aura, but I'm having problems with having them launch projectiles. In my cannon object, I have a create event and two alarms.
Create:
--- Code: ---alarm[0]=0;
--- End code ---
Alarm 0:
--- Code: ---var i;
for(i = 0; i < 3; i++) {
alarm[1] = 25;
}
alarm[0] = 100;
--- End code ---
Alarm 1:
Creates moving instance of the cannon ball object moving upwards at speed 3
Unfortunately, nothing happens when I run the game. Any help would be appreciated. Thanks!
Kyir:
Though this doesn't exactly answer your question, I'd honestly just say alarms are more trouble than they're worth when it comes to things like this. You would probably have an easier time with setting a variable in create and then just ticking it up/down in step until it reaches a certain point, then executing whatever action you want and resetting the variable.
patrickgh3:
Here's a snippet of a basic cannon using alarms: https://klazen.com/gm/QVK
Let me also tell you what's wrong with the code you posted. By default, all alarms start out at 0. Alarms will only trigger if you set them to a value above 0, and then they count down back to 0 later. So, setting alarm[0] to 0 does nothing; the alarm event will never trigger! If you want the alarm to trigger immediately, you can set it to 1.
In your alarm 0 event, you set alarm[1] to 25 three times over, which is unnecessary. The alarm will only trigger once, not three times; that's just how alarms work.
In regards to what Kyir said about emulating alarms yourself, I think which method you use depends on personal preference and context. In one-off objects like this cannon I might prefer to use alarms to keep things simple. In more complex objects, I might prefer to do it manually.
BaronBlade:
--- Quote from: patrickgh3 on November 27, 2015, 08:13:36 AM ---Here's a snippet of a basic cannon using alarms: https://klazen.com/gm/QVK
Let me also tell you what's wrong with the code you posted. By default, all alarms start out at 0. Alarms will only trigger if you set them to a value above 0, and then they count down back to 0 later. So, setting alarm[0] to 0 does nothing; the alarm event will never trigger! If you want the alarm to trigger immediately, you can set it to 1.
In your alarm 0 event, you set alarm[1] to 25 three times over, which is unnecessary. The alarm will only trigger once, not three times; that's just how alarms work.
In regards to what Kyir said about emulating alarms yourself, I think which method you use depends on personal preference and context. In one-off objects like this cannon I might prefer to use alarms to keep things simple. In more complex objects, I might prefer to do it manually.
--- End quote ---
Alright, I understand what you're saying about alarms. However, when I try to implement that code snippet, GMS throws me this error:
ERROR in
action number 1
of Alarm Event for alarm 0
for object objCannon:
Creating instance for non-existing object: 448
at gml_Object_objCannon_ObjAlarm0_1 (line 3) - new_cannonball = instance_create(objCannonBall, self.x, self.y)
I do have an object called objCannonBall, which only deletes upon hitting a block, so I'm perplexed.
Sudnep:
--- Quote from: BaronBlade on November 27, 2015, 09:56:07 AM ---
--- Quote from: patrickgh3 on November 27, 2015, 08:13:36 AM ---Here's a snippet of a basic cannon using alarms: https://klazen.com/gm/QVK
Let me also tell you what's wrong with the code you posted. By default, all alarms start out at 0. Alarms will only trigger if you set them to a value above 0, and then they count down back to 0 later. So, setting alarm[0] to 0 does nothing; the alarm event will never trigger! If you want the alarm to trigger immediately, you can set it to 1.
In your alarm 0 event, you set alarm[1] to 25 three times over, which is unnecessary. The alarm will only trigger once, not three times; that's just how alarms work.
In regards to what Kyir said about emulating alarms yourself, I think which method you use depends on personal preference and context. In one-off objects like this cannon I might prefer to use alarms to keep things simple. In more complex objects, I might prefer to do it manually.
--- End quote ---
Alright, I understand what you're saying about alarms. However, when I try to implement that code snippet, GMS throws me this error:
ERROR in
action number 1
of Alarm Event for alarm 0
for object objCannon:
Creating instance for non-existing object: 448
at gml_Object_objCannon_ObjAlarm0_1 (line 3) - new_cannonball = instance_create(objCannonBall, self.x, self.y)
I do have an object called objCannonBall, which only deletes upon hitting a block, so I'm perplexed.
--- End quote ---
instance_create(x,y,object)
not instance_create(object,x,y)
Navigation
[0] Message Index
[#] Next page
Go to full version