Count Only Picked Instances

0 favourites
  • 6 posts
From the Asset Store
An educational game for counting pictures. An easy to use template for developers to build larger games
  • What's a good way to count only specific instances based on PVs that I can send to a Global?

    I thought I'd try

    For Each MOB

    MOB.happiness >= MOB.maxhappy

    --> set global : happyMOBs = MOB.Count

    However MOB.Count doesn't pick the instances I intended to pick, instead counting every instance, whether the MOB is happy or not. How sad.

    Open to suggestions!

  • I think what you want is the countmatching("object") expression that CC had. It would return the number of picked instances. It would be very useful!

    Currently you can use a for each and add to a variable.

  • MOB.Count would return the number of instance of MOB. Can't you just add 1 to happyMOBs when the condition is met!

  • Unfortunately, unless I use a trigger once, a For Each won't work, because it will just add 1 every tick, but I need it to run dynamically so it can detect when a MOB becomes happy, unhappy, or dead.

    A workaround would be to place the "add 1" as trigger once actions in each MOB's happiness handler. A "countmatching" action would give me far more control though. Feature request?

  • Couldn't you just set the variable to 0 each time before the for each? It'll add 1 to the variable however many times there are instance of the object picked.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Fantastic! That did the trick nicely.

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