Long for loop and loading bar.

Get help using Construct 2

Post » Wed Apr 13, 2016 5:59 pm

Message: Roy2 can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
Hi. I have a very long for loop, with thousands of iterations, on a loading layout. I wanted every iteration to add 0.00001 (for example) to a variable, and then set the loading bar to that variable every iteration, so you can see how it loads. But it justs takes a while, and then set the bar to the final value without any increment in the iterations.

I've read this tutorial https://www.scirra. com/tutorials/723/using-wait-in-loops , and tried using waits with loop index, or just setting the variable at 0.00001*loopindex, but it didn't work. Any tips on this? Thanks a lot.
B
7
S
2
G
1
Posts: 17
Reputation: 534

Post » Wed Apr 13, 2016 6:37 pm

A loop will start and finish in the same tick. If you don't get another tick, you won't get an update.

You can use a counter variable to increment your for loop to break up your loop into multiple frames

Lets say you need For Loop from 0 to 20000.

CounterVariable=0

You can do For Loop from CounterVariable*1000 to (CounterVariable*1000+999)
CounterVariable<20

Add another event after to increment CounterVariable by 1 while CounterVariable<20 (this should NOT be in the loop).

This will break your 20000 interations into 20 ticks - 0 to 999, 1000 to 1999, 2000 to 2999, ect.

Change the amount of iterations you want to process per frame for different resolutions of progress.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Wed Apr 13, 2016 7:26 pm

oosyrag wrote:A loop will start and finish in the same tick. If you don't get another tick, you won't get an update.

You can use a counter variable to increment your for loop to break up your loop into multiple frames

Lets say you need For Loop from 0 to 20000.

CounterVariable=0

You can do For Loop from CounterVariable*1000 to (CounterVariable*1000+999)
CounterVariable<20

Add another event after to increment CounterVariable by 1 while CounterVariable<20 (this should NOT be in the loop).

This will break your 20000 interations into 20 ticks - 0 to 999, 1000 to 1999, 2000 to 2999, ect.

Change the amount of iterations you want to process per frame for different resolutions of progress.



I didn't thought that. Thanks a lot, i can't wait to implement it!
B
7
S
2
G
1
Posts: 17
Reputation: 534


Return to How do I....?

Who is online

Users browsing this forum: AndreasR, tarek2 and 12 guests