How do I show progress during Array iteration?

0 favourites
  • 6 posts
From the Asset Store
Progress\Loading Bar. Now Load you game like a Professional.
  • I am iterating through a very large array using For each element. Because of the size of the array and the calculations done to its contents this takes a long time, and I would like to show some kind of progress to the user during the calculations. The problem is that For each element locks the operations. Neither setting a text nor logging to the browser works within the iteration. I've tried other ways, like inserting a wait statement or updating a global variable which is shown from another event, but without success.

    How can I show how far the iteration has gone during a For each element event?


  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I don't think you can do this with For Each Element, you need to use System-For loops.

    See this demo:

  • Thanks for the answer and the example! I have changed my code accordingly and now it works fine.

  • It turns out that I was mistaken. My code doesn't work fine with large arrays. These are my events (CurrentColumn is a local static number defined above):

    With the wait statement in event 32 enabled, Construct just goes through the Array very fast, but the entire loop ends before everything is actually loaded. It doesn't seem to wait the 0,5 seconds per CurrentColumn. With the wait statement disabled, the Array eventually loads as intended and the browser prints log messages during the loop, but Chrome says that the page is not responding and the progress bar is not updated during the loop.

    I am using this to load a very large csv file, exported from Tiled and containing 400 times 400 tiles, so the calculation of each row takes quite some time, up to 1.5 seconds. I have tried with different wait times, up to two seconds, but without success. I guess that I am doing some obvious mistake here, but can't figure out what it is.

  • You need to use "wait 0.5*loopindex" in the first line, not your static variable.

    The first loop (for "IndexX") is actually executed in one tick, but it creates many Wait threads. If you use static variable, at this time it's 0, so all these threads will become "Wait 0". If you use loopindex, then they will be scheduled with 0.5s increments.

  • Of course! I have now changed the wait statement and the progress bar updates as it should. Thanks!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)