counting the amount of objects that have a certain value

This forum is currently in read-only mode.
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Basically, I want to count how many objects (different objects and all their instances) have the variable "selected" set to "yes" and set the value of global variable "unitCount" to the amount counted. However, I don't want to add to the global variable each time "selected" is set to "yes" since it would make certain controls in my project more difficult to make. Any help is appreciated. If there is no way, please let me know. Thanks.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 1.ALWAYS -> set unitCount to 0

    2.obj selected="yes"

    ___for each obj ->add 1 to value unitCount

    Make sure to set unit count to 0 every frame with the "always", as shown.

    I call this type of setup a flush variable, because they never keep their value for more than 1 frame. Event order will matter greatly when using these, because you have to make sure your events which reference unitCount take place after the variable is "filled", otherwise it will just always return zero. Hope this helps!

  • Or you could use the object.count or countmatching("object") expressions.

  • Thanks, after looking into it, I think both ways will work for what I need it too. I'll test them out and see which one works best. Thanks a lot!

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