# [CAPX] Summation of instance variables?

Get help using Construct 2

### » Tue May 09, 2017 8:05 pm

I'm attempting to sum by loops but I'm getting endlessly increasing sum.
Only way I found was to go brute force and sum every instance one by one.

https://www.dropbox.com/s/v9yjbaeb7a7k2 ... .capx?dl=0
Last edited by MPPlantOfficial on Tue May 09, 2017 8:54 pm, edited 1 time in total.
"The intent is to provide subscribers with a sense of pride and accomplishment for unlocking different features...."
B
40
S
17
G
32
Posts: 818
Reputation: 20,629

### » Tue May 09, 2017 8:32 pm

Can't find "Sprite Bank".
B
71
S
22
G
281
Posts: 3,842
Reputation: 154,886

### » Tue May 09, 2017 8:48 pm

blackhornet wrote:Can't find "Sprite Bank".

Oh shoot that wasn't supposed to be there. You know how to do the summation though?
"The intent is to provide subscribers with a sense of pride and accomplishment for unlocking different features...."
B
40
S
17
G
32
Posts: 818
Reputation: 20,629

### » Tue May 09, 2017 8:50 pm

A loop would do it. You have to reset your sum to 0 at the beginning.
B
71
S
22
G
281
Posts: 3,842
Reputation: 154,886

### » Tue May 09, 2017 8:57 pm

blackhornet wrote:A loop would do it. You have to reset your sum to 0 at the beginning.

I don't understand. Wouldn't resetting sum every loop index give me the value of the last instance only?

(0) Set SUM to 0, Add Sprite(loopindex).VALUE to SUM
(1) Set SUM to 0, Add Sprite(loopindex).VALUE to SUM
(2) Set SUM to 0, Add Sprite(loopindex).VALUE to SUM
.
.
.

Like this?
"The intent is to provide subscribers with a sense of pride and accomplishment for unlocking different features...."
B
40
S
17
G
32
Posts: 818
Reputation: 20,629

### » Tue May 09, 2017 9:07 pm

Sprite:VALUE=1 -> SUM_VAL = Sprite.PickedCount
B
71
S
22
G
281
Posts: 3,842
Reputation: 154,886

### » Tue May 09, 2017 9:32 pm

blackhornet wrote:Sprite:VALUE=1 -> SUM_VAL = Sprite.PickedCount

Sweet. I don't even understand how this works but thank you.
"The intent is to provide subscribers with a sense of pride and accomplishment for unlocking different features...."
B
40
S
17
G
32
Posts: 818
Reputation: 20,629

### » Tue May 09, 2017 9:52 pm

MPPlantOfficial wrote:
blackhornet wrote:Sprite:VALUE=1 -> SUM_VAL = Sprite.PickedCount

Sweet. I don't even understand how this works but thank you.

Here is one example :

Capx: https://www.dropbox.com/s/irznaydpqhbtvx9/Total%20Sum.capx?dl=0
B
51
S
31
G
95
Posts: 421
Reputation: 53,233

### » Tue May 09, 2017 10:36 pm

blackhornet wrote:Sprite:VALUE=1 -> SUM_VAL = Sprite.PickedCount

Hi.
I tried this modifying the picked count condition to
Value > 0 yet the Picked Count still gives it a value of '1'.

Using the brute force method I could have a values of 100s but the picked count method would still say '6'
"The intent is to provide subscribers with a sense of pride and accomplishment for unlocking different features...."
B
40
S
17
G
32
Posts: 818
Reputation: 20,629

### » Tue May 09, 2017 11:25 pm

You'll have to provide an example again.
B
71
S
22
G
281
Posts: 3,842
Reputation: 154,886

Next