Trigger once for every object

For questions about using Classic.

Post » Sun Dec 04, 2011 12:09 am

Coming back from about a year's worth of no work with Construct, my Construct-fu seems to be a little rusty and I can't figure out what to do with the following coding dilemma.

Basically I'm trying to get an enemy to shoot in bursts when the player is in range, thus the enemy has turret behavior and "On Shoot" plays its shooting animation. The animation repeats 3 times and with every repetition fires a shot. Problem is that unless I use the "Trigger once while true" condition, the system will make more than one bullet spawn when the animation hits the appropriate frame. However, simply using this condition of course causes problems when numerous enemies are shooting simultaneously because some of them won't fire since the condition being true for one enemy overrides another's shooting sequence.

I tried sticking a "For Every Object" loop for the enemies and this seems to alleviate the problem somewhat, but the problem still crops up quite often. I've also tried playing around with the order of the conditions and tried using "Pick Object" commands but still can't seem to get it to work as intended. How would I go about coding something like this?

Here is a picture of the events in their current state:
B
34
S
15
G
16
Posts: 267
Reputation: 10,684

Post » Sun Dec 04, 2011 2:13 am

Try to place For each EnemySoilder as main event and the rest as sub-events.
B
54
S
11
G
4
Posts: 250
Reputation: 5,074

Post » Sun Dec 04, 2011 3:55 am

Hmm, tried that and a few other possibilities and after experimenting with it a bit more I've come to the conclusion that apparently with the For Each loop I can solve the problem. However... for some reason it still happens from time to time that an enemy will play the shooting animation but not fire. Funnily enough they still do this even if I remove the For Each loop and Trigger Once condition, so I'm guessing the problem here isn't necessarily the coding but perhaps an engine limitation of some sort. Weird.
B
34
S
15
G
16
Posts: 267
Reputation: 10,684

Post » Mon Dec 05, 2011 1:21 am

Try the "On animation frame change" condition instead of "for each" and "trigger once".
B
79
S
24
G
54
Posts: 4,743
Reputation: 40,749

Post » Mon Dec 05, 2011 5:28 am

Marvelous, that seems to fix everything for the most part with some animation tweaks. Strangely some enemies will sometimes only fire twice instead of three times when there's a lot of them shooting, but I can definitely live with that if some further tweaking won't resolve it. Thanks for tip kind sir
B
34
S
15
G
16
Posts: 267
Reputation: 10,684


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests