Count objects matching a private variable

For questions about using Classic.

Post » Mon Jun 21, 2010 12:53 pm

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.
B
46
S
23
G
7
Posts: 459
Reputation: 6,763

Post » Mon Jun 21, 2010 1:31 pm

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.
B
2
S
2
G
3
Posts: 406
Reputation: 2,062

Post » Mon Jun 21, 2010 1:39 pm

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

:)
B
46
S
23
G
7
Posts: 459
Reputation: 6,763

Post » Mon Jun 21, 2010 1:40 pm

- 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
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Mon Jun 21, 2010 1:51 pm

Thanks Lucid. Works great. :)
B
46
S
23
G
7
Posts: 459
Reputation: 6,763


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 0 guests