How do I count each objects on the layout...

Get help using Construct 2

Post » Tue Jun 20, 2017 11:41 am

How do I count how many objects are appear in the layout?

I also use an action to create 10 same sprite objects with different size.
So how can I count objects with more condition like count number of object that only has width greater than 250pixels. (The other objects created with less than 250pixels don't count.)
B
13
S
2
Posts: 31
Reputation: 699

Post » Tue Jun 20, 2017 12:07 pm

Same sprites? use the pick all event. System, pick all.

So if you had a sprite named box you create the even under system - pick all.

Object (pick the box)
expression would be self.width
comparison > (greater than)
value = 250
B
23
S
11
G
4
Posts: 69
Reputation: 3,439

Post » Tue Jun 20, 2017 4:11 pm

skrotar wrote:Same sprites? use the pick all event. System, pick all.

So if you had a sprite named box you create the even under system - pick all.

Object (pick the box)
expression would be self.width
comparison > (greater than)
value = 250


Thank you so much!! I have never known that it could be this simple to pick something with special property.
By the way, is it a way to know how many objects we have picked?
I'm struggling with having Text to show how many '250<obj' is on the screen. I've used trigger add+1 to global variable when true and -1 when destroyed but it was not functioning individually.
B
13
S
2
Posts: 31
Reputation: 699

Post » Tue Jun 20, 2017 4:23 pm

Create a variable to store the numbers (lets call it count)

Then do a for event, for each sprite make the action add 1 to count
B
23
S
11
G
4
Posts: 69
Reputation: 3,439

Post » Tue Jun 20, 2017 4:37 pm

Life saving! "For each" does the trick.
Thanks. :D
B
13
S
2
Posts: 31
Reputation: 699

Post » Tue Jun 20, 2017 4:42 pm

There is also mysprite.count that does that.
B
16
S
3
Posts: 69
Reputation: 1,048

Post » Tue Jun 20, 2017 5:24 pm

WackyToaster wrote:There is also mysprite.count that does that.

Thanks for another the suggestion.
I've changed to something like mysprite.PickedCount and it woks best for me.
B
13
S
2
Posts: 31
Reputation: 699


Return to How do I....?

Who is online

Users browsing this forum: jbr190, NN81, Yahoo [Bot] and 33 guests