How do I get the count of sprites for an instance variable?

Get help using Construct 2

Post » Sun Apr 20, 2014 11:30 am

Let's say I have (10) Monster sprites with an instance variable called BreedingPitUID. (5) of the Monster sprites have a BreedingPitUID of 121 and the other (5) have a BreedingPitUID of 139. How do I get the count of all the Monster sprites with a BreedingPitUID of 121? I've tried objectcount and Sprite.PickedCount ... neither is giving me what I need.
B
17
S
3
Posts: 33
Reputation: 1,666

Post » Sun Apr 20, 2014 12:09 pm

@phatkidsoftware - you could do a For Each loop of Monster sprites while checking if MonsterSprite->BreedingPitUID = 121, then increment a global or local variable to keep track.
B
33
S
7
G
8
Posts: 312
Reputation: 8,528

Post » Sun Apr 20, 2014 1:17 pm

Use Pick by comparison, then PickedCount.
You do not have the required permissions to view the files attached to this post.
ImageImageImage
B
71
S
22
G
249
Posts: 3,763
Reputation: 138,577

Post » Sun Apr 20, 2014 3:42 pm

@blackhornet - that's a cool way of doing it. I learn something new every day. Thanks.
B
33
S
7
G
8
Posts: 312
Reputation: 8,528

Post » Mon Apr 21, 2014 11:00 am

Does the picked count work with families?
B
17
S
3
Posts: 33
Reputation: 1,666

Post » Mon Apr 21, 2014 11:21 am

Seems like the pick works, except if there are no sprites of the family type created ... the highlighted line never seems to fire ... see the attachment.
You do not have the required permissions to view the files attached to this post.
B
17
S
3
Posts: 33
Reputation: 1,666

Post » Mon Apr 21, 2014 1:50 pm

Correct. The Pick event will evaluate to False, so you add an Else to it to get the case where there were none picked.
ImageImageImage
B
71
S
22
G
249
Posts: 3,763
Reputation: 138,577

Post » Mon Apr 21, 2014 5:05 pm

That was it! Thank you blackhornet!
B
17
S
3
Posts: 33
Reputation: 1,666


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 13 guests