How do I destroy objects with the same instance variables?

Get help using Construct 2

Post » Fri Jun 26, 2015 6:35 pm

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?
B
20
S
4
Posts: 51
Reputation: 1,104

Post » Fri Jun 26, 2015 9:23 pm

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".
B
19
S
3
G
1
Posts: 29
Reputation: 1,038

Post » Sat Jun 27, 2015 10:13 am

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...
B
20
S
4
Posts: 51
Reputation: 1,104

Post » Sat Jun 27, 2015 11:19 am

use instance variables
B
251
S
39
G
15
Posts: 1,964
Reputation: 40,723

Post » Sat Jun 27, 2015 11:32 am

Lordshiva1948 wrote:use instance variables

var=1 is instance variable
B
20
S
4
Posts: 51
Reputation: 1,104

Post » Sat Jun 27, 2015 12:31 pm

bangoo wrote: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.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Sat Jun 27, 2015 1:14 pm

Similar to nimos100, but Pick does the work.
www.blackhornettechnologies.com/Constru ... Links.capx
ImageImageImage
B
71
S
22
G
240
Posts: 3,734
Reputation: 133,994


Return to How do I....?

Who is online

Users browsing this forum: tarek2 and 19 guests