How do I save level completion time to an array?

Get help using Construct 2

Post » Fri Nov 07, 2014 4:46 am

What I would like to do is save the time that is remaining on the countdown timer to a "cell" on an array and when you beat the level that number will be displayed on the level that you just completed i.e "Best Time:" & bestTimeArr.At(location where current time left is stored in the array). I would like the countdown timer to save a new value to a new "cell" in my array for each level. I just can't figure out how to make the "Timer" ES save to a new cell in the array, each time. Any ideas? Basically how do I tell the "EndOfLayout" event to store the current Countdown timer value to a new cell in the array every time?
B
7
S
1
Posts: 26
Reputation: 497

Post » Fri Nov 07, 2014 5:31 am

Create an array that is simple and corresponds to the number of levels you have. For example, if you have 30 levels, create an array with a width of 30 would be nice. From there on, save each best time at the appropriate array. Level 1 will be at array cell 0 and etc.

And I wouldn't use at the end of layout for this. I would trigger it once your condition for winning that level is met. For example, you win if all the enemies are killed. I would do the check at that event. You should use a variable to save the current level completed time, than compare it with the value in the array. And if variable < array value, delete the array value, insert the new best time from the variable into the array, and save.
B
46
S
23
G
31
Posts: 693
Reputation: 20,637

Post » Fri Nov 07, 2014 5:38 am

rekjl wrote:Create an array that is simple and corresponds to the number of levels you have. For example, if you have 30 levels, create an array with a width of 30 would be nice. From there on, save each best time at the appropriate array. Level 1 will be at array cell 0 and etc.

And I wouldn't use at the end of layout for this. I would trigger it once your condition for winning that level is met. For example, you win if all the enemies are killed. I would do the check at that event. You should use a variable to save the current level completed time, than compare it with the value in the array. And if variable < array value, delete the array value, insert the new best time from the variable into the array, and save.

Is there anyway to save the countdown timer value into a new slot on the array everytime? can I tell it to check to see if the previous cell in an array is already "filled" with a variable and then it moves to the next empty cell to save the new variable?
B
7
S
1
Posts: 26
Reputation: 497

Post » Fri Nov 07, 2014 6:04 am

Nevermind I figured it out. I just set each individual Array Cell to correspond to the countdown timer at the end of the cells corresponding level i.e Level 1 is cell 0, Level 2 is cell 1 and so forth and so on. Thanks for the pointer rekjl!
B
7
S
1
Posts: 26
Reputation: 497

Post » Fri Nov 07, 2014 4:27 pm

No problem UnitDTH. Also something that I forget to mention. It is best to do two event checks for the arrays. One to check if the array value is smaller than the time variable, and another if the array value is 0 (which means that it is empty and contains no value). I am sure you can see the problem now, If you do a event check timevariable <array, than set new array and save, it will never save because the empty value when first check is 0 and will always be less than timevariable.

This is usually what I do,

1st event,
timevariable < Array, value at (?)
-delete that value and add the new time variable in, and save

2nd event,
Array, value at (?) = 0
-delete that value and add the new time variable in, and save
B
46
S
23
G
31
Posts: 693
Reputation: 20,637


Return to How do I....?

Who is online

Users browsing this forum: Artcadev, brunopalermo and 19 guests