How do I Use Picked Count?

Get help using Construct 2

Post » Sat Mar 18, 2017 4:42 am

I'm trying to figure out if all enemies are killed EXCEPT ones with a Boolean attached.

So I'm doing a

if Enemies(family).Boolean = True
compare if Enemies.PickedCount = 0

Action "level complete"

However. It doesn't seem to work properly. I have a button that destroys all enemies for testing, and when I do that, the pickedcount stays as is from the start of the layout. When I play the level normally - it goes down as I kill enemies one by one except once it gets to 1 enemy, it won't go to 0. Am I missing something?
B
38
S
12
G
1
Posts: 527
Reputation: 4,087

Post » Sat Mar 18, 2017 4:55 am

have a capx with the issue isolated?
Mistakes were made.
B
49
S
24
G
107
Posts: 1,581
Reputation: 60,303

Post » Sat Mar 18, 2017 6:09 am

https://dl.dropboxusercontent.com/u/28104568/PickedCountBug.capx

@oosyrag - I've made a new project. I believe it's either a limitation or a bug. @Ashley - any idea about this?
B
38
S
12
G
1
Posts: 527
Reputation: 4,087

Post » Sat Mar 18, 2017 7:43 am

It is not a limitation. I believe you are using it incorrectly.

The reason the counter does not change on kill all is that the event only triggers if a sprite with "countme" set to true exists. Pickedcount for an Object will never return 0 if you do it in any kind of event that picks instances of that object meeting a condition, because events with conditions trigger only after at least one instance meeting the conditions is found (assuming there is no condition set by you to tell it "if picked count>X", then you would need x+1). Also the event changing the counter is before the event destroying the enemies. What happens is:

Tick 1
1) counter is changed to reflect current number (5)
2) button was pressed, destroyed all (after counter last updated)

Tick 2
1) no enemies exist and thus the condition for updating the counter is not met. This is why you see the initial number as the set text action does not execute at all.

The proper way to do this would be as in the attached capx, use a subevent in a event block with no conditions, check if any marked with "countme" enemies exist in one subevent, else in the other subevent set counter to 0 (as they don't exist).

https://www.dropbox.com/s/pdj2npl3h0tu1 ... .capx?dl=1
B
15
S
6
Posts: 85
Reputation: 1,195

Post » Sat Mar 18, 2017 4:40 pm

@Pulstar - Ahh, I suppose that makes sense. Thank you!!
B
38
S
12
G
1
Posts: 527
Reputation: 4,087


Return to How do I....?

Who is online

Users browsing this forum: bluesun66 and 3 guests