Trigger once for every object

This forum is currently in read-only mode.
From the Asset Store
Change the size and position of everything without calculating anything!
  • 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:

    <img src="http://www.majhost.com/gallery/Zulag/Screenshots/constr.jpg" border="0" />

  • Try to place For each EnemySoilder as main event and the rest as sub-events.

  • 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.

  • Try the "On animation frame change" condition instead of "for each" and "trigger once".

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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 <img src="smileys/smiley16.gif" border="0" align="middle" />

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)