Finding the Sum of an Array in the Step event

I've tried to find the sum of an array by using the following code
CREATE EVENT
for loop......
value[1] = 1
value[2] = 1 all the way to value[40] and every single one is worth the value one
STEP EVENT

for i=1; i<=40; i++)
{
global.sum = global.sum + value
}


The problem is (like expected) it starts incrementing during the game many times while going through the STEP EVENT..... I should end up with the value 40 but it keep incenting throughout the game because of the STEP EVENT running throughout the game... how do I make so it's a solid number with the summation of the values
 

kburkhart84

Firehammer Games
Move the code to some event that doesn't run every step...like just after the code there in the create event.

The other option would be to have a variable that is false created in the create event, then in the step event, check if its false, do the code if it is, and set it true. Then the next step, it will skip that because of the if statement. This method is a workaround and isn't necessarily the best way to do it in this case, although it is commonly used in other scenarios(like when you want complex code to only run every 5 steps, you can use a counter variable).
 
Top