How do I count number of objects with specific variable value?

0 favourites
  • 3 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hello

    I have a sprite called Bugs with a local variable called Player. The values for the local variable are 1, 2, 3 or 4.

    I need to count how many of them have the variable set to 1, how many to 2 etc. and save that to global variables. I tried using compare variable and pickedcount like so:

    - Bugs (variable) Player = 1 --> set 1x to Bugs.pickedcount

    the "1x" is the global variable.

    This works fine until the value is 0 - meaning there are no Bugs that have Player variable set to 1. I understand that if the condition isn't met the action isn't triggered and I will never get a 0 this way. But I really need that 0...

    So, how can I count the number of Bugs objects that have their Player variable set to 1 and get that number even if it's 0?

    Thank you :)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Else : set global var to 0

  • Right... I keep forgetting about Else :/

    Thank you very much, you are a life saver!

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