How do I count an instance variable?

Get help using Construct 2

Post » Tue Apr 25, 2017 5:37 pm

Hello

The npc sprite have an instance variable which called "task" and it is a text variable. This variable can be movetower or woodcutting or idle and so on...

So I need to set a global variable which include the total amount of idle npc. I have to count only the idle values.

I tried to use the pick by comparison and a few more fuction but these are not working. Can you write me an easy solution please?

Thanks in advance!
B
5
S
1
Posts: 37
Reputation: 441

Post » Tue Apr 25, 2017 5:45 pm

Use the pickedcount expression.

https://www.scirra.com/manual/133/common-expressions


npc sprite variable = "idle", set global value to npc sprite.pickedcount
B
43
S
23
G
20
Posts: 735
Reputation: 12,027

Post » Tue Apr 25, 2017 7:30 pm

I tried this but it is still not working. I dont know what is the problem...
B
5
S
1
Posts: 37
Reputation: 441

Post » Tue Apr 25, 2017 7:34 pm

Are you using .pickedcount and not .count?

.count will count all instances where as .pickedcount will only count the picked instances, as the names suggests.
B
43
S
23
G
20
Posts: 735
Reputation: 12,027

Post » Tue Apr 25, 2017 7:43 pm

Oo my god.. i got it! the proplem was that i wrote with upper case letter the i in the instance variable but i use lower case at the conditions... no comment :)

So i use this now:
Pick by comparison. ---- set global var - npc.pickedcount

Working properly now that i know its case sensitive.

Thanks
B
5
S
1
Posts: 37
Reputation: 441


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, kentoy, Yahoo [Bot] and 33 guests