Count Only Picked Instances

Get help using Construct 2

Post » Sat Apr 14, 2012 11:45 pm

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!
B
58
S
20
G
7
Posts: 305
Reputation: 8,804

Post » Sat Apr 14, 2012 11:48 pm

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.
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Post » Sun Apr 15, 2012 12:13 am

MOB.Count would return the number of instance of MOB. Can't you just add 1 to happyMOBs when the condition is met!
B
28
S
9
G
6
Posts: 30
Reputation: 6,609

Post » Sun Apr 15, 2012 12:16 am

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?
B
58
S
20
G
7
Posts: 305
Reputation: 8,804

Post » Sun Apr 15, 2012 2:30 am

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.Arima2012-04-15 02:31:58
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Post » Sun Apr 15, 2012 2:40 am

Fantastic! That did the trick nicely.
B
58
S
20
G
7
Posts: 305
Reputation: 8,804


Return to How do I....?

Who is online

Users browsing this forum: theosciandra and 24 guests