How to know the sum of instance values ?

Get help using Construct 2

Post » Fri Aug 26, 2016 12:57 pm

Hello,

Is it possible to know the sum of instance values of an object ?

By example, in my game, there are several birds. Each one have an instance value called "ChronoCount" which add 1 to a global value, every 0.05 sec, everytime ChronoOnOff = 1. And I need to get the sum of all instance values "ChronoCount" (in real time). I tried with "Pick by comparaison" (cf picture), but it's not working. It just count one bird at a time.

Image

Thanks

Image
Image
B
9
S
1
Posts: 22
Reputation: 586

Post » Fri Aug 26, 2016 2:56 pm

@rcmedy2

You could use Add Bird.PickedCount*Bird.ChronoCount to Joie_Count.
B
17
S
9
G
5
Posts: 74
Reputation: 4,145

Post » Fri Aug 26, 2016 3:19 pm

Just use that last condition. Pick bird with ChronoCount = 1.
Now the expression bird.pickedcount is the sum that you need.

I see (think) that is see that you intended to use sub events, but did not.
Stuff to read: https://www.scirra.com/manual/128/sub-events
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri Aug 26, 2016 5:44 pm

Thanks for your replies

(I just noticed my second action was wrong... It's not "add Bird.ChronoCount to Joie_Count" but just add 1, otherwise it increases exponentially).

I tried with @SimoneT solution , it's working but I have now an issue if I want to stop adding. It's only working when "Every tick", if "every 0.05 sec" the global value doesn't stop exactly at the same time of the instance value. I would like to manage the speed of adding. I have something like that :

Image


Image
Last edited by rcmedy2 on Fri Aug 26, 2016 5:48 pm, edited 1 time in total.
Image
B
9
S
1
Posts: 22
Reputation: 586

Post » Fri Aug 26, 2016 5:47 pm

@99Instances2Go I didn't understand what you mean with sub events
Image
B
9
S
1
Posts: 22
Reputation: 586

Post » Fri Aug 26, 2016 6:55 pm

Is ok, i see now that i captured that wrong.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 29 guests