Sprite.Count condition isn't working? (Solved)

0 favourites
From the Asset Store
An educational game for counting pictures. An easy to use template for developers to build larger games
  • This is a piece of of my level building code that spawns enemies. For testing purposes I wanted to limit it to only create 1 enemy. So I made a new condition: Enemy.Count = 0, as seen below.

    BUT, regardless if that condition is there, it still creates multiple enemies. Shouldn't that condition always stop spawning enemies after 1 has been created?

    Tagged:

  • even though the condition should be invalid after the first is created, have you tried using trigger once while true to see if it eliminates the issue?

  • Adding Trigger Once didn't change anything, but I think that's because that event runs multiple times as it's going through the array to build the level.

    As another test I added an instance variable to the Enemy that sets it = to the current Enemy.Count right after it is spawned:

    And checking them in the bebugger, they are setting the Count correctly:

    And lastly I made a static variable that hold the current Enemy.Count and then tests that variable as a condition. And that actually works as intended. Now I'm only getting 1 enemy spawning.

    So, how can it be setting the Enemy.Count correctly when setting a variable but then not when used as a Condition? Is this a bug?

  • Try <1

  • Try <1

    I tried that, but I'm getting the same result.

  • I created a C3P example if anyone wants to test if for themselves. I'm just trying to determine if this is intended behavior or a bug.

    dropbox.com/s/3ksh1jcubyfkxr6/Sprite.Count.c3p

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The system compare values condition does not pick any instances.

    The enemy.count expression returns the current number of picked instances. Since you don't pick any in your event, it is always 0.

    Add a pick all enemy condition before it and it will work.

    Edit: My mistake, I had forgotten there were specific pickedcount and count expressions.

  • try this.

    if Enemy.count > 0: do nothing

    Else: execute your actions

  • Add a pick all enemy condition before it and it will work.

    This does work, and I think I get why I was getting the result that I was.

    The only problem now is that if there are no instances of the Enemy then Pick All won't trigger the event. I'm sure I can find a decent workaround, though. Thanks!

  • Objects aren't fully created until the next top-level event. So Enemy.Count won't be updated until the loop finishes. Just use a local variable and set it to Enemy.Count before the loop, then check Variable = 0, and increment Variable for each Create.

  • oosyrag

    The enemy.count expression returns the current number of picked instances. Since you don't pick any in your event, it is always 0

    The object.count does not only return picked instances, it returns all instances. object.pickedcount returns picked instances only

  • From my experience, object Count can't be 0. It won't detect zero presence of any instance.

  • The object.count does not only return picked instances, it returns all instances. object.pickedcount returns picked instances only

    I was wondering about this, too. Thanks for explaining that. But I have to say.. it's weird that object.count requires objects to be picked even though no matter how many are picked it's always going to give the same number. Shouldn't there be a way to count objects without picking them?

    Objects aren't fully created until the next top-level event. So Enemy.Count won't be updated until the loop finishes. Just use a local variable and set it to Enemy.Count before the loop, then check Variable = 0, and increment Variable for each Create.

    This is what I am going to try. It's just always disappointing when something as simple as counting the number of sprites has to have a workaround.

  • alextro robit_studios

    Object.count does not require objects to be picked, and object.count will return 0 if there are no instances.

    Example: 1drv.ms/u/s!AkmrWgxeuxlKhIdmWEW-ADRkwVTESA

    Looking at your original post, if I replicate the same events, using a variable instead of an array value it works correctly and only spawns a single object.

    Was that array value condition nested underneath other events?

  • calminthenight I fully understand that Count just counting all instances and PickedCount is counting based on meet certain condition since I use them a lot. Counting something didn't exist is not counting.

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