I Wanna Community

Fangames => Game Design => Programming Questions => Topic started by: BaronBlade on November 26, 2015, 11:02:00 PM

Title: Looping Actions?
Post by: BaronBlade on November 26, 2015, 11:02:00 PM
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: [Select]
alarm[0]=0;
Alarm 0:
Code: [Select]
var i;
for(i = 0; i < 3; i++) {
    alarm[1] = 25;
}

alarm[0] = 100;

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!
Title: Re: Looping Actions?
Post by: Kyir on November 27, 2015, 07:32:12 AM
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.
Title: Re: Looping Actions?
Post by: patrickgh3 on November 27, 2015, 08:13:36 AM
Here's a snippet of a basic cannon using alarms: https://klazen.com/gm/QVK (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.
Title: Re: Looping Actions?
Post by: BaronBlade on November 27, 2015, 09:56:07 AM
Here's a snippet of a basic cannon using alarms: https://klazen.com/gm/QVK (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.

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.
Title: Re: Looping Actions?
Post by: Sudnep on November 27, 2015, 09:59:45 AM
Here's a snippet of a basic cannon using alarms: https://klazen.com/gm/QVK (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.

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.
instance_create(x,y,object)
not instance_create(object,x,y)
Title: Re: Looping Actions?
Post by: BaronBlade on November 27, 2015, 11:02:35 AM
instance_create(x,y,object)
not instance_create(object,x,y)

:paraPalm: I guess I should have checked how that function worked. Thanks, sudnep!