Count objects matching a private variable

This forum is currently in read-only mode.
From the Asset Store
An educational game for counting pictures. An easy to use template for developers to build larger games
  • 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.

  • Try Construct 3

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

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

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