0 Favourites

Count objects matching a private variable

This forum is currently in read-only mode.
  • Hi guys I'm having trouble with this.

    I have multiple instances of the same sprite in my layout, they have a private variable that is set by random at the start of layout, the variable is either 0 or 1.

    What I'm having a problem with is counting the number of the instances that have their private variable as 1 and setting a global variable to this number.

    I have tried to use "count object matching events" but it only counts them by instance name what is the syntax for adding a check for a private variable as well.

    Eg - 10 instances / 6 have the PV 1 / 4 have the PV 0

    - Set global variable to 6

    Or is there a better way of doing this.

    Also the private variable can change too, so the global variable has to keep up to date.

  • Can't you set the global variable to zero and then use "for each object" to increase the global variable by 1 each time it finds the private variable value your looking for?

    Unless you have several hundred instances, I don't see why this wouldn't work well enough.

    Just set it up as a function and call it when required.

    Krush.

  • I've tried that too. But the global variable will just keep increasing by 1. Even using "trigger once" doesn't help.

    *EDIT*

    Just had another try while typing this and stupid me had the "trigger once" in the wrong place. Working fine now.

    Thanks Krush

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
    • yourobject pv is equal to 1

    ----set global to countmatching

    You just have to have a condition that picks the object you want to count

  • Thanks Lucid. Works great.

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