How do I show loading bar during function

Get help using Construct 2

Post » Mon Sep 11, 2017 8:02 pm

I have a huge, extensive function that generates a 100,000 tile map, but I cannot for the life of my figure out how to display the loading progress to the user. I have tried making a loading bar and updating it from inside of the loops but it seems to skip past everything and still just freezes for 12 seconds. My suspicion is that everything is happening inside of one game tick, but if that is true what is a good way to give the game time to update the visual for the user in between?
B
11
S
3
Posts: 24
Reputation: 723

Post » Tue Sep 12, 2017 1:07 am

Yes, you are probably doing everything in one tick.
Have you tried inserting Wait 0.1 here and there in your function to allow the screen to refresh?

Just be aware that function "forgets" its parameters and all local variables after the Wait. You need to store them in global variables or somewhere else.
Check out my awesome game Doptrix
B
17
S
9
G
51
Posts: 839
Reputation: 28,487

Post » Tue Sep 12, 2017 5:59 am

The wait command doesn't seem to work It seems more like it is issuing 100,000 wait 0.1 second commands all at the same time. I might rework this to only continue to generate level under a certain amount of FPS. cpuutil or some command like that if that.

UPDATE: It seems to work very easily in segments outside of the loops. I can cycle through generating terrain, ore, trees and update the player before each task by using a 0.1 wait just like you said! Thank you!
Last edited by Zamargo on Tue Sep 12, 2017 6:51 am, edited 1 time in total.
B
11
S
3
Posts: 24
Reputation: 723

Post » Tue Sep 12, 2017 6:49 am

Well, of course you shouldn't place Wait into your main loop which you repeat 100.000 times.
You should make sure it's called no more than 10-100 times.
Here is an example:
Image

Another thing you can try is to modify your function so that it will only generate part of your 100,000 tile map, for example 10,000 tiles.
When the function ends, it updates the progress bar and starts a timer for 0.1s.
After 0.1s the timer calls this function again and the next 10,000 tiles are generated.
Repeat this until the entire tile map is filled.
Check out my awesome game Doptrix
B
17
S
9
G
51
Posts: 839
Reputation: 28,487

Post » Tue Sep 12, 2017 6:58 am

I have it working now thanks to you guys.

Eventually as a side project I want to learn to process the tasks using a fps kept in calculation by rotating logo. Maybe even one using cpuutil expressions. Ultimately I think keeping track of progress in the current task/loop and only operating enough per tick to be limited by cpuutil or fps and reporting the progress at the end of the tick would be the best way to report loading and one day I shall make it happen.
B
11
S
3
Posts: 24
Reputation: 723

Post » Tue Sep 12, 2017 9:13 am

So how did you get the loading bar working?
Could you post a screenshot?
Check out my awesome game Doptrix
B
17
S
9
G
51
Posts: 839
Reputation: 28,487


Return to How do I....?

Who is online

Users browsing this forum: maranpis, totoe and 34 guests