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!
Develop games in your browser. Powerful, performant & highly capable.
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.
Fantastic! That did the trick nicely.