destroy with certain instance variable

Just started using Construct 2? Post your questions here

Post » Tue Mar 08, 2016 4:31 pm

I've searched but I can't find anything with this particular thing I'm trying to do so I hope you can help me!

I have a trash can button, and when I press that I want to destroy instances with a certain instance variable. I know how to do it if it's just one object with different instances, but I don't know how to do it with different objects at the same time.
Hope you understand!
B
10
S
3
Posts: 62
Reputation: 774

Post » Tue Mar 08, 2016 4:41 pm

Put everything in a Family, with that variable, then you can just do Pick Family.Var = X -> Family.Destroy
ImageImageImage
B
71
S
21
G
220
Posts: 3,648
Reputation: 123,725

Post » Tue Mar 08, 2016 7:43 pm

Thanks! Could you explain just a bit more how I do that, I mean, do I add a condition to when the trash can sprite is being clicked? Do I choose Pick by Comparison there? I'm just so confused. When I choose Pick by comparison, it says "expression" and I cant find the variable I've created there so I don't get it.
As you can hear, I'm still learning hehe. Not used to using variables.
B
10
S
3
Posts: 62
Reputation: 774

Post » Tue Mar 08, 2016 9:04 pm

You can simply do Family > Compare Variable. The actions will only apply to the objects of the family that fulfill that condition

See How events work
B
83
S
22
G
15
Posts: 1,039
Reputation: 15,219

Post » Wed Mar 09, 2016 10:30 am

Ok but hm.. The thing I'm trying to do is, (it's an interior decorating game) create a bunch of sprites here and there. And then you can select one sprite (you click on it and a small menu appears). Then you can rotate it and so on, and also delete it.
So if the user has created multiple instances of a table for example, I only want the selected table to be destroyed and not all instances.
When I tried to put all furniture sprites in a family and add a variable to the family, then it destroys all the furniture :/

Here is an test version so you can see https://dl.dropboxusercontent.com/u/624 ... utton.capx
B
10
S
3
Posts: 62
Reputation: 774

Post » Wed Mar 09, 2016 1:49 pm

Don't work with both object types, just the one. 'selected' is accessible from each object now. You can do this either way: use only Family, or use only each object type:
On tap furniture -> furniture:selected=1

OR

On tap chair -> chair:selected=1

Event 2 is correct.

(I'd suggest using 'On touched object' - 'On tap' is a specific gesture, and doesn't always work as you'd expect, for simple selections).
ImageImageImage
B
71
S
21
G
220
Posts: 3,648
Reputation: 123,725

Post » Thu Mar 10, 2016 10:51 pm

Read about Families here. You can't mix families and the objects they contain. If you have a condition that uses a family, the action also has to use the family, and not a single object from it
B
83
S
22
G
15
Posts: 1,039
Reputation: 15,219


Return to Beginner's Questions

Who is online

Users browsing this forum: Baidu [Spider] and 0 guests