PickedCount never returns zero.

0 favourites
  • 10 posts
From the Asset Store
“Zero Numbers” is a logic game. Game with Source-Code (Construct 3 / .c3p) + HTML5 Exported
  • 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?

  • 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.

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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 :)

  • 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.

  • 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 :)

  • 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.

  • 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 :)

  • Whoops - I stand corrected. Sorry about giving out incorrect info, and thanks Ashley for pointing that out.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)