How do I delete all instance of a particular type?

  • I have now tried several way to delete all instances of a object, but can't seem to get it to work.

    What is the best way to remove all instances of a object from the game.

    Example:

    The game of chess is over and and wanner remove all the pawns so I can insert them again for the next game.

  • For each "Object" -> Destroy Object?

  • Event for removing all instances.

    Add event (system --> pick all)

    Choose instance.

    Add action (destroy)

    If this wont work then posting a capx would be helpfull for those whith answers.

    Goodluck!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • This removes the visually from the game, but if I do a For each "Object" -> someAction right after they are still there.

    So if I add 10 objects, foreach object destroy, add 10 object and finally foreach object something, the loop iterates 20 times, even thought I only see 10 objects on the screen.

  • Event for removing all instances.

    Add event (system --> pick all)

    Choose instance.

    Add action (destroy)

    If this wont work then posting a capx would be helpfull for those whith answers.

    Goodluck!

    Ill try to post an example..

  • > Event for removing all instances.

    >

    > Add event (system --> pick all)

    > Choose instance.

    > Add action (destroy)

    >

    > If this wont work then posting a capx would be helpfull for those whith answers.

    >

    > Goodluck!

    Ill try to post an example..

    Here is an example:

    dl.dropbox.com/u/19522040/destroyProblem.capx

  • Here is your corrected example

    What's the point of spawning instances and destroying them in the same row anyway ?

    Also it had more to see with the order and how events work.

  • Here is your corrected example

    What's the point of spawning instances and destroying them in the same row anyway ?

    Also it had more to see with the order and how events work.

    There is no point! :-) It was just an example to illustrate that I got an unexpected result from performing a series of actions.

    If i create x object, iterate and destroy them, I should end up with zero objects. My example just demonstrates that this is not what happens.

  • Using a family maybe?

  • > Here is your corrected example

    >

    > What's the point of spawning instances and destroying them in the same row anyway ?

    >

    > Also it had more to see with the order and how events work.

    There is no point! :-) It was just an example to illustrate that I got an unexpected result from performing a series of actions.

    If i create x object, iterate and destroy them, I should end up with zero objects. My example just demonstrates that this is not what happens.

    Here is a different version of my example that works.

    dl.dropbox.com/u/19522040/destroyProblem.capx

    I understand why this works, but I'm still puzzled that the first version did not.... Well Ill try to make this work in my game.... Thanks for the feedback/help.

  • Because your first version used several "Start of layout" events.

    In the end they were combined to be only one.

    So it was like if you created instances, destroyed them, added some more, all in a row in a single tick.

    Once again it is a matter of order and how events work.

    Also in your current version, you don't need the event 3.

    Just have an action "Pawn _ Destroy" in the event 2 (on Destroyer clicked) it will delete/apply to all instances of pawn.

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