How do I Count Instances With A Variable of A Certain Value

Get help using Construct 2

Post » Fri Dec 11, 2015 4:24 am

I have a game that has a lot of the same sprites on screen with different abilities depending on a variable that defines their class. So class one blocks act differently from class 2 blocks, but they are the same object. This is necessary because the objects need to be able to switch between these modes quickly. I need to also be able to count how many of the object with a certain class there are in the game (i.e. how many blocks with their class set to 2 are in the layout). Is there a simple way to do this? I can provide screenshots of event sheets if needed.
B
8
S
1
G
1
Posts: 19
Reputation: 1,093

Post » Fri Dec 11, 2015 4:51 am

Just use "Pick by comparison" to find your value and then Sprite.PickedCount contains the count.
ImageImageImage
B
71
S
20
G
191
Posts: 3,535
Reputation: 108,844

Post » Fri Dec 11, 2015 5:05 am

Hi,
Add an instance variable (example: "Class number") to your object.
To check how many there are you can write:

System: Every tick >
(sub-event) Object: compare instance variable (value=x) > System: set Global variable to Object.PickedCount

Hope this helps!
B
16
S
9
G
5
Posts: 74
Reputation: 4,120

Post » Fri Dec 11, 2015 5:08 am

...I am dumb.

Thank you for the quick response!
B
8
S
1
G
1
Posts: 19
Reputation: 1,093


Return to How do I....?

Who is online

Users browsing this forum: imhotep22, ItsAstro, Yahoo [Bot] and 2 guests