Using an Object Timer to create an object once for each instance

Here is what I’m basically trying to do:

I have multiple instances of an enemy on screen, and I’m using an object timer (and each instance has their own individual timer, as far as I can tell). Whenever this timer reaches a certain value, I want to create an object “DodongoFireBreath” at a point on the object called “Mouth”. So in my code (screenshot below), when the variable “State” of the object “Dodongo” = “Breathe Fire” and the timer “FireBreathAttack” is greater than or equal to .5 seconds, I want each instance of Dodongo to create the DodongoFireBreath object at its “Mouth” point.

Since the goal is to create an object, I have a Trigger once condition in the event to do this. However, this is causing the DodongoFireBreath object to be created on one instance and not the other when their timers overlap one another (since the condition was already met once and fired once, it won’t fire again). So my next thought is to use a For Each event. However, when doing that, you aren’t supposed to have a Trigger Once under it. If I don’t use Trigger Once to create the DodongoFireBreath object, the object will be created over and over on every frame (and I don’t want that). So I need a Trigger Once somewhere, I assume.

So how can I create a single instance of this DodongoFireBreath object on each instance of Dodongo after the timer “FireBreathAttack” is greater than or equal to .5 seconds without using a Trigger Once condition? Or is this possible with a For Each event without a Trigger once condition, in some way?

It seems that Trigger Once and multiple instances of objects don’t work together. So I’m asking for help on how to do something like this when it involves creating a single instance of an object once for each instance of an enemy.

Here is the screenshot of the code:

Thank you all in advance!

I liked the concept, so I played around with it. You need a for each object and an object boolean to track the state. I decided to add a tween to grow the fireball and linking to connect the dragon to the fireball. There might be a better way but I like this.

Try me, please ignore my crude doodle of the dragon. Click the dragon to shoot or drag.

The dragon has the draggable behavior, the fireball has the tween and destroy off screen behaviors.
The dragon has a point on its mouth named ball as in fireball.

The only variable is on the dragon.

project (click the green [code] and select download zip

Thanks for this info. And I’m definitely not one to judge anyone’s crude doodle of a dragon when I’m not much of an artist myself. Lol

I’m going to try to take after your code in your example and work it into my game for the Dodongo enemies later today when I get a couple hours to play with it. In the meantime, just to make sure I completely understand what you’re saying:

It seems like creating the DodongoFireBreath object (or fireball in your example) should happen with a Trigger Once, before the For Each loop. You set a boolean state to true in the Trigger Once event, then check for it below that, then run the For Each as a subevent of the boolean check.

Is it necessary to link the fireball to the dragon in your example for this to work, or did you do that for other reasons?

I need to figure out where to work in the AngleToPlayer check into this, but again, I’ll play around with it later today and report back. Thank you for your help Keith!

You can use an object variable. A trigger once would apply to the object not the instance. An object boolean would work like a trigger once for instances.

I used the link to place the growing fireball in the dragons mouth should the dragon moves before the fireball is released. It matches the fireball with the dragon. If there was only 1 dragon or it didn’t move then I don’t think the link would be needed.

Since you would already have a time, You also wouldn’t need the cool down timer that I used. Your version would already have a timer.

Yes, I would use an object variable.

So I think I found a solution, although it might be considered “sloppy”. Here is the code:

I used a boolean as you suggested, but when I was trying to create the DodongoFireBreath object in the first event with the Trigger Once, I was getting weird results. So, I added a For Each and used the timer “FireBreathAttack” to create the DodongoFireBreath object when the timer is between .5 and .6 seconds (such a short period of time that it looks like it only creates a single instance of the object). This is to get around putting the creation of the DodongoFireBreath object in the Trigger Once above. Then, I linked the Dodongo and the DodongoFireBreath object so that each individual DodongoFireBreath object is created/deleted based on the object timer “FireBreathAttack” of the Dodongo which it is linked to.

Any thoughts about doing it this way? Or issues you might see later on?

As you said, it could be optimized but I’m not at my PC and I have trouble testing that type of logic with my head.

My only thought is the timer. Instead of trying to capture the time between .5 and .6 you could use > .5 with animation = “idle” that way the animation would be like a boolean.