How do I sum the elements in an array with a loop

Get help using Construct 2

Post » Tue May 20, 2014 4:30 pm

Hi there!

I need to add up all the elements in an array to get their total sum, so I tried using a loop in order not to make an action for each element in the array, but it keeps on looping forever.

It looks like "x = x+1" doesn't work only once per loop cycle in Construct 2 as in other programming languages. It keeps on adding endlessly.

I made and attached a simplified CAPX file for your analysis.

Thanks in advance!

thegreatozon
You do not have the required permissions to view the files attached to this post.
B
6
S
3
Posts: 5
Reputation: 567

Post » Tue May 20, 2014 4:37 pm

You need to put your loop inside something that only happen 1 time.

Check my solution.
You do not have the required permissions to view the files attached to this post.
B
11
S
3
Posts: 39
Reputation: 814

Post » Tue May 20, 2014 4:52 pm

joaoanhas wrote:You need to put your loop inside something that only happen 1 time.

Check my solution.


Thanks for your help, joaoanhas! I couldn't see your file because I didn't install the new beta version yet, but I got the idea from your comment.

All the best,

thegreatozon
B
6
S
3
Posts: 5
Reputation: 567


Return to How do I....?

Who is online

Users browsing this forum: BreadCrowns and 36 guests