Count object

For questions about using Classic.

Post » Sat Dec 26, 2009 2:08 pm

Family.Count should correctly be counting all objects in the family. Post a .cap showing what you mean.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Sat Dec 26, 2009 2:22 pm

[quote="eski":sj2kzxit]Maybe one more thing.
Can i count items that are in a familie.
I cant use Family.Count because then it only counts the family giving me 1 but there are 3 items in the family.[/quote:sj2kzxit]
Family Count, counts instances of objects made on a layout.
so say had a sprite with a blue family and another sprite with a blue family added to them.
So if you had 2 object of the blue family there on a layout it will say "2".

If you want to count Families like [color=#0000FF:sj2kzxit]blue[/color:sj2kzxit], [color=#FF0000:sj2kzxit]red[/color:sj2kzxit], and [color=#00FF00:sj2kzxit]green[/color:sj2kzxit] families would give you a count of 3 then, no you can't do that.
B
21
S
4
G
4
Posts: 280
Reputation: 2,934

Post » Sat Dec 26, 2009 3:55 pm

Are you saying you want to count how many families an object has in the events? Why do you need to do that? I can't imagine any reason.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Sun Dec 27, 2009 6:03 pm

No i want to count how many items are in a family. I have 3 items on the layout, they are all in the Items family. When i count them i with Items.Count i get 1.

You can see how it works in this cap.

[url:3cqo4lxr]http://www.internet.is/eski/testing-hide.cap[/url:3cqo4lxr]
B
7
S
1
G
3
Posts: 66
Reputation: 1,651

Post » Mon Dec 28, 2009 3:12 am

[quote="eski":1mxwbwrf]No i want to count how many items are in a family. I have 3 items on the layout, they are all in the Items family. When i count them i with Items.Count i get 1.

You can see how it works in this cap.

[url:1mxwbwrf]http://www.internet.is/eski/testing-hide.cap[/url:1mxwbwrf][/quote:1mxwbwrf]

like I sad family count count the instances of objects so each one of your objects only have 1 instance so the count would be 1.

So if you want to count all object as a private variable to the family call it count
then add all the objects counts to it.

I see what you want it to do. Maybe the Dev will add a "get number of all objects" that add up all the objects instances connected to the family in the next build.
B
21
S
4
G
4
Posts: 280
Reputation: 2,934

Post » Mon Dec 28, 2009 5:23 am

downloaded the cap and tested it with 997.
edit: now I get it.

Explanation proper:

Item.Count is picking an object to refer to from the Item family. Then it's applying the Count function on it. So it's 1.

In order to get all the instanced objects in that family, you'll have to ask for each and sum them all. Note that you won't be going through each object TYPE, but through each object INSTANCE. So, add 1 for each.

always
-global('sum') = 0
foreach item
-global('sum') = global('sum')+1

there you have the total of instanced objects.
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Mon Dec 28, 2009 11:40 am

Allright.. i undertstand it now toralord..
i used the method that madster suggested, worked out fine .. :D

Thank you.
B
7
S
1
G
3
Posts: 66
Reputation: 1,651

Post » Mon Dec 28, 2009 5:19 pm

Thanks for the .cap - I had a look and it's actually a bug. Items.Count should report 3 since there are 3 objects in the Items family! That's fixed in the next build.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Mon Dec 28, 2009 6:45 pm

Thats super..
Keep up the good work :D
B
7
S
1
G
3
Posts: 66
Reputation: 1,651

Previous

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests