Identical objects with private variables skipping events

This forum is currently in read-only mode.
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • I'm having a little issue here. I have an object with Private Variable "Health" on the layout I want to take damage, then to be destroyed, THEN immediately respawn outside the screen after it is destroyed.

    Works fine with groups of objects, works fine by themselves when they're destroyed individually, but say two (or more) happen to get destroyed at the same time, it only registers one object as being destroyed, despite the fact that two have been destroyed. Thus in my scenario, where I want a new object to be created when another object is destroyed, I only have one new respawned object, despite the fact two have been destroyed.

    For instance, if I systematically destroy two objects at a time (on purpose), I can slowly dwindle the respawning objects to 1 object on screen, despite the fact that I may require 20 enemies on the screen at once. Of course, once I'm down to 1 enemy left you can't kill two at a time, so, at that point the private variable thing isn't really an issue. haha.

    It's not a big deal, but it is something I've run into. I'm experimenting with different applications of weapons that a player can upgrade to, and it seems like occasionally I'll start with a group of 8 or 9 enemies, and after a little bit of playing I'm down to 3 or 4. I want to start using larger projectiles and beams that can destroy a couple of enemies at a time, but if they're destroying all at once and not all performing the same actions I want then I may have to rethink how to do this by hiding, say, 20 projectiles at a time, behind a dummy "laser beam" graphic.

    Anyway to get around this?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Do you have a simple "Is overlapping" event handling the destruction of your enemy objects? The way I'm assuming this is happening is this:

    1. Two enemies overlap beam

    2. Two enemies are destroyed

    3. Spawn routine kicks in because "enemy is destroyed"

    4. Spawn routine only creates one enemy

    What you might want to do is a For Each loop during your check for enemy overlap, like so:

    +For each enemy.sprite
    +Enemy.sprite overlaps beam.sprite
       -Destroy enemy.sprite
       -Add 1 to global('spawn')
    [/code:2xd3vwpp]
    
    Then later when you do your spawning code, do like so:
    
    [code:2xd3vwpp]
    +Global('spawn') > 0
       +Loop global('spawn') times
          -System: Create object enemy.sprite at x, y
    [/code:2xd3vwpp]
    
    That way you always spawn the same number of enemies that you kill.
  • I was just typing up a similar solution using 'For each' . That'd be the way to ensure all matching objects get created, as deadeye said.

  • Awesome. That is exactly what I was looking for. Thanks guys.

    You guys are fast. lol.

  • No sweat, let us know how it works out

  • Yeah, just for reference, here's what's going on here. If you have something like

    + Sprite Health < 0

    -> Sprite: Destroy

    -> Create 'explosion' at Sprite

    If by chance two or more Sprites have Health < 0 at the same time (eg. a button to destroy them all), then multiple objects will be picked by the 'Health < 0' condition. The 'Destroy' action is called once per picked instance, but system actions have no regard for picked objects, and only run once. So you only get one explosion. Adding the for-each forces it to run the actions repeatedly for each instance, so you get enough explosions as well. This is true of any system action.

  • Another way to do it, though it would be a little sloppier is to have a "counter" object which has the number of "bad guys" that you want to have... and compare that to the actual number of bad guys each time one or more is killed...

    essentially if the number of bad gys is less than the counter number, then spawn bad guys until the number is equal.

    deadeye's way of doing it is way cleaner though.

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