Count certain instances but not the others

For questions about using Classic.

Post » Thu Apr 05, 2012 4:26 am

Hey there,

I just can't figure out how to count only certain instances of an object, but not the others.
For example, say I have 4 visible instances of the object, and 6 invsible ones. You know what Object.count is going to return? 10, yes.

Say I want to count only the visible instances of that object... what do I do?

Thanks in advance to anyone who can answer me!

Kan
B
11
S
3
G
3
Posts: 206
Reputation: 2,379

Post » Thu Apr 05, 2012 4:32 am

First, use a condition: is sprite visible.

Then after that, use the expression countmatching("sprite"). That will return the number of picked instances of the object.
Moderator
B
87
S
32
G
33
Posts: 3,005
Reputation: 27,397

Post » Thu Apr 05, 2012 4:49 am

It works fine if the condition is "is sprite visible", but it doesn't work when it's a "is sprite overlapping ..." :-/
Like, I create a red area, and I want to count only the instances overlapping it. But even if there are several ones, it says "1" anyway.
B
11
S
3
G
3
Posts: 206
Reputation: 2,379

Post » Thu Apr 05, 2012 5:04 am

I think "Is sprite overlapping" focuses on a single object. Instead, can you try checking if the red area is overlapping the sprite, then do the countmatching("sprite") expression?
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Thu Apr 05, 2012 5:39 am

It works! Thanks a bunch!

And have a nice springtime. :)
B
11
S
3
G
3
Posts: 206
Reputation: 2,379

Post » Fri Apr 06, 2012 4:33 am

Ah really glad to hear it worked. Thanks Kan, you too!
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests