How do I run a loop once for each instance?

1 favourites
  • 12 posts
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • The problem: I can't realize how to create strictly two instances of laser beam FOR EACH enemy_top. Enemy tops are filtered by instance variable "shock", then each of them must create two beams. It would seem simple, but... The code:

    This is one of the code variations that doesn't work as expected.

    Tagged:

  • The top condition is technically a for each you don't need to embed another for each inside it.

  • The top condition is technically a for each

    If you mean filtering by instance variable at the top - yes but, the small loop "For" below that create two beams runs indefinitely OR create two beams only for a single instance when used with trigger once.. Instead I need to run this small "For" loop ONCE FOR EACH of enemy_top... So two beams are created for each enemy_top...

  • Based on what I'm seeing in the first part of that event this should be split into two events anyway if you want something to be checked indefinitely and then another thing to run once. 106-108 should be one event. 109 onwards you can move into its own event - a loop with trigger once. The top part of the event matters a lot.

  • Use boolean instead of trigger once. So the logic is when a boolean switched state the action won't executed further more.

  • Use boolean instead of trigger once. So the logic is when a boolean switched state the action won't executed further more.

    How do you see it in the context of my screenshot above?

  • Using a boolean in place of a trigger once condition does not resolve the problem, the issue is that you are trying to trigger once inside a loop that is running every tick. The fix is to split it into two events because one needs to run every tick and one doesn't. But again this is just repeating my last post.

  • ...because one needs to run every tick and one doesn't...

    Sure, but how to call the event block with "For from 1 to 2" to run once per each instance that meets the condition at the top, even if I will split these events up? The code on screenshot below creates beams endlessly as well...

  • Returning to your original question and the design, you want it to create just 2 beams only. The question is when? Right now you create it constantly, when do you want it to spawn the beams? If for example it's every 2 seconds then you can add a condition every 2 seconds.

  • ...you want it to create just 2 beams only. The question is when?..

    So, I have a few enemies on layout. They can shoot when they see the player (instance boolean "is shooting"), so when some of the enemies "is shooting" and their weapon is "shock" - they spawn two beams (each of enemy who shoot with "shock").

  • So there is a condition at 105 that enemy has LOS in that event which you've decided to cut off in the screenshot?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • So there is a condition at 105 that enemy has LOS in that event which you've decided to cut off in the screenshot?

    No, all the events for this effect is under [if weapon = "shock"], event 105 is for another weapon. However I already solved the problem by creating these two beams [on "enemy spawn" function] and then set it invisible with width zero. Then when the enemy fires, I take further action.

    Thank you guys for your answers anyway!😄

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