Pick all instances not picked by preceding block of events?

0 favourites
  • 3 posts
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • Curious how others would solve what I'm trying to achieve. Let's say I have a Sprite object called Blue, with two instances on the layout.

    Blue #1 is overlapping only Red and Yellow Sprite objects.

    Blue #2 is overlapping only Yellow and Green Sprite objects.

    Overlapping any Red, Yellow, or Green causes Blue to "die," but with a different animation depending on which color "killed" it. In the case of Blue overlapping multiple colors, the priority is Red, then Yellow, then Green.

    So Blue #1 is considered to be killed by Red, and Blue #2 is considered to be killed by Yellow.

    I want to write event logic that, in plain English, does:

    • Pick Blues overlapping Red, play the "Death by Red" animation
    • For Blues not picked, pick Blues overlapping Yellow and play the "Death by Yellow" animation
    • For Blues still not picked, pick Blues overlapping Green and play the "Death by Green" animation

    In a conventional programming language I would iterate through every instance of Blue, and run each through a series of If Then - Else If - Else conditions. (Or Case - Switch.) And originally I thought I could use C3 Else conditions, but that was before I understood the Else condition is only met if the previous event didn't run for any instance of Blue -- if even one Blue is overlapping Red, my "Else If Overlapping Yellow" block won't run even for the Blues not overlapping Red. (I also misunderstood that Else doesn't pass through unpicked Blue instances from the previous Event -- all instances revert to unpicked.)

    I could add more conditions to each subsequent event, for example for the Yellow overlap test, I could say "Pick Blues that are not overlapping Red and are overlapping Yellow." And the next event could be "Pick Blues that are not overlapping Red and not overlapping Yellow and are overlapping Green". The disadvantage here is that in my real project, the conditions are considerably more complicated and there are many more events, so it would be very bulky--by the time I got to the last event, I would have a huge list of negative conditions to test for to make sure I'm only picking the instances not picked by one of the preceding Events.

    The best solution I can think of is to use an instance variable to flag when an instance has been dealt with -- in this case, "isKilled" or something ("Play Death by Red animation and set isKilled to True"). Then each subsequent event could exclude any instance who have isKilled = True.

    Is there a more natural way in C3 to handle this?

    (P.S.- My actual scenario is using Custom Movement to do elaborate testing for overlap at many different offsets to determine what action to take ... Often the Sprite will meet the conditions of more than one test so I have a priority order. And since many of those actions are Push Out of Solid, which immediately change the position of the Sprite, that movement then makes the Sprite meet the conditions of overlap tests below it. I was using Else blocks which worked fine when I had only one instance, but when scaling to multiple instances things went a bit crazy.)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can do it the same way as you did with one instance with else’s. Just add a “for each blue” event and put the events you used before as sub events. That way it will only be looking at one blue instance at a time.

    “For each” is usually the solution when something works with one instance and you want to make it work with multiple.

  • Thank you! I'm not sure I would have figured this out on my own. To be honest, the documentation covering For Each is a little cryptic and I wasn't sure when I'd need to use it. I still had to think about it for a while after your post until it finally made sense.

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