counting the amount of objects that have a certain value

For questions about using Classic.

Post » Wed Oct 20, 2010 10:38 pm

Basically, I want to count how many objects (different objects and all their instances) have the variable "selected" set to "yes" and set the value of global variable "unitCount" to the amount counted. However, I don't want to add to the global variable each time "selected" is set to "yes" since it would make certain controls in my project more difficult to make. Any help is appreciated. If there is no way, please let me know. Thanks. :D
B
2
G
2
Posts: 48
Reputation: 746

Post » Thu Oct 21, 2010 2:55 am

1.ALWAYS -> set unitCount to 0

2.obj selected="yes"
___for each obj ->add 1 to value unitCount


Make sure to set unit count to 0 every frame with the "always", as shown.

I call this type of setup a flush variable, because they never keep their value for more than 1 frame. Event order will matter greatly when using these, because you have to make sure your events which reference unitCount take place after the variable is "filled", otherwise it will just always return zero. Hope this helps! :D
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620

Post » Thu Oct 21, 2010 5:26 am

Or you could use the object.count or countmatching("object") expressions. :)
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Post » Fri Oct 22, 2010 1:57 am

Thanks, after looking into it, I think both ways will work for what I need it too. I'll test them out and see which one works best. Thanks a lot! :D
B
2
G
2
Posts: 48
Reputation: 746


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests