How do I destroy objects with the same instance variables?

0 favourites
  • 7 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • I have two type of objects:

    "A" with the variable "1" and "B" with the same variable "1".

    How do I destroy "B" with the Variable "1" if all of the objects "A" with the same Variable are destroyed?

  • so...

    I'm guessing what exactly the scenario is.

    You've got object "A" and object "B", and they each have a variable (let's call it "var").

    You're trying to destroy all instances of "A" and "B" that have variable "var" set to 1?

    If that's the case...

    Put "A" and "B" into a family.

    Remove the variable from both object types.

    Now select the family in the Project panel, under "Families".

    In the Object Properties panel, create a variable for that family.

    Rework your events to use the family instead of "A" and "B".

  • A little remark:

    There are multiple enemies with the same var="1": A1, A2, A3, A4 etc.

    All these enemies are connected with the object "B" which also has var="1".

    Player destroyes enemies A1, A2... but can't destroy B.

    I need to eleminate B if all A with var "1" are destroyed.

    There are other enemies on screen with var 2,3...

  • use instance variables

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • use instance variables

    var=1 is instance variable

  • I have two type of objects:

    "A" with the variable "1" and "B" with the same variable "1".

    How do I destroy "B" with the Variable "1" if all of the objects "A" with the same Variable are destroyed?

    You can do it like this:

    Int TestForObjects = 0 (Just a local variable for testing)

    For each ObjectA

    ---- if ObjectA.var = 1 set TestForObjects = 1

    If TestForObjects = 0

    ---- Pick ObjectB.var = 1

    -------ObjectB.Destroy

    So if you found any ObjectA with a variable = 1 you change TestForObjects to 1, since it is by default 0 you know that if it goes through all objectA and is still 0 after the loop then there are no objectA with that value. So you can put it in a function and every time an ObjectA is destroyed you call the function. And then you of course just change the 1 to Function.param(0) and pass the value you want to test against to the function.

  • Similar to nimos100, but Pick does the work.

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