PickedCount never returns zero.

Discussion and feedback on Construct 2

Post » Wed Dec 12, 2012 8:45 am

I've seen a couple of other people mention this but not seen a real answer. I've noticed that pickedcount always returns 1 when it should be returning 0. Is this supposed to happen and is there a workaround?
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Wed Dec 12, 2012 8:52 am

If you think about it, it should only return a value whenever an object is picked.

This is because of the nature of conditions; they only fire if there are any objects matching the conditions.

E.g. compare Sprite.X = 0 - all sprites that match this condition will pass and PickedCount will show the number of objects. But as you reduce the number of sprites (by moving them off the axis), the PickedCount will reduce.

But what happens when you remove the last sprite? The condition no longer is valid and doesn't execute associated actions. In that case, there are no objects on SOL, nothing to run PickedCount on. I'm not sure where it gets the value from. Perhaps @Ashley can clarify this.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Wed Dec 12, 2012 8:56 am

When there are no objects to pick, it presumably just skips the whole process, but you would have thought that it would start out with zero and therefore pass zero as a result? It's a bit awkward because I genuinely need to know how many objects I have in a certain situation, including if there are zero. I'm having to use a local variable and set it to 0, then set it to the pickedcount if it makes it to the next subevent, then test that later.
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Wed Dec 12, 2012 9:25 am

Mipey's right. If you do something like:

If sprite is visible
If sprite.pickedcount = 0

Then if no sprites are visible, c2 stops running the event after 'if sprite is visible' returns false and proceeds to the next event, not even getting to the second condition. There are no situations where the sol has 0 picked instances of something and c2 continues running aces. You're thinking about it backwards - c2 doesn't start with no instances picked - it starts with ALL of them picked, then whittles the list down.

To find out if no objects meet a criteria, I have an event that checks, for example, if an object is visible - then an else event after it, which only runs if the above event didn't run, meaning none are visible.Arima2012-12-12 09:36:31
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Post » Wed Dec 12, 2012 9:50 am

Yeah you're right, I am thinking about it backwards. Still strange how it comes up with the number 1 though.

But your solution does the trick anyway, just do an else block, that'll solve it :)
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Wed Dec 12, 2012 9:57 am

It's actually not strange - if there is at least one instance selected, the aces will keep running. If you have one instance in the layout, that is the max pickedcount can return. If you have 10 instances, at the start of the event sheet it will return 10 instead.

If you have an example of code you want explained, post it and I'll explain what it's doing.
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Post » Wed Dec 12, 2012 10:19 am

I can't post because my game is over 500 events now.

So in this case, there are 11 spaceships. 10 are set to team 1, and 1 is set to team 2. When I ask for the number of ships from team 2, it correctly returns 1. If that ship is then destroyed and I ask for ships from team 2 with again, it returns 1 still.

I could understand if it returned 10 (all the existing ships) or 0 (the correct answer).

It's not hugely important now since I've worked around it, but if you want to go ahead and explain, that's cool - no harm in my brain knowing what's going on :)
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Wed Dec 12, 2012 2:10 pm

Like with creating objects, objects aren't really destroyed until the next top level event. This is by design; beginners often make events with actions like "destroy enemy, create explosion at enemy.x, enemy.y" which would not work if the enemy was really immediately destroyed. In accordance with this, the object count and picked count still include an object flagged as destroyed until it's really destroyed at the next top-level event.

Also, it is possible for PickedCount to return 0, but only in an OR block. Consider:
SpriteA condition
- or -
SpriteB condition
It's possible no SpriteAs meet their condition, but because a SpriteB does, the whole event runs - but no SpriteAs are picked.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Wed Dec 12, 2012 4:28 pm

Cheers Ashley. Actually that's handy to know about the destroyed objects because I'd noticed that behaviour myself and wasn't quite sure why it was working as it did. Now I know :)
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Wed Dec 12, 2012 6:47 pm

Whoops - I stand corrected. Sorry about giving out incorrect info, and thanks Ashley for pointing that out.
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Next

Return to Construct 2 General

Who is online

Users browsing this forum: Lordshiva1948, MonDieu and 11 guests