Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

My Loading Assets Screen Is Inefficient?

Asked by
Aepeus 59
7 years ago

I am trying to make a loading screen which displays the assets loaded percentage but I feel like there is a way to shorten this, and sometimes it doesnt work (print)?

repeat wait() until script.Parent.Loading
local max = game.ContentProvider.RequestQueueSize
print("Loading")
while game.ContentProvider.RequestQueueSize > 0 do
    local progress = ((-1 * game.ContentProvider.RequestQueueSize) + max)
    local e = progress / max
    print(game.ContentProvider.RequestQueueSize)
    print(e .. "%")
    wait(.1)
    script.Parent.Loading.Text = "Loading Assets " .. e .. "%"
end
script.Parent.Loading.Text = "Finished!"
0
It keeps printing 0% at print(e .. %) Aepeus 59 — 7y
0
Why the need to do all those calculations? e-e Why not just (All - Current) / All, or something like that for the calculations? TheeDeathCaster 2368 — 7y

1 answer

Log in to vote
0
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
7 years ago

As @TheeDeathCaster said, you can shorten your calculation a bit. To solve the problem with "0%" you can use math.ceil.

repeat wait() until script.Parent.Loading
local provider = game:GetService('ContentProvider');
local max = provider.RequestQueueSize
print("Loading")
while provider.RequestQueueSize > 0 do
    local e = math.ceil((max - provider.RequestQueueSize) / max)
    print(provider.RequestQueueSize)
    print(e .. "%")
    wait(.1)
    script.Parent.Loading.Text = "Loading Assets " .. e .. "%"
end
script.Parent.Loading.Text = "Finished!"

It should work fine, but if it doesn't, you can also use the new math.clamp function to clamp it between 1 and 100.

Hope this helped.

0
Wouldn't line 1 cause a problem? It's set to directly get the object and not check. Also, I checked out line 6; when I tested it out of curiosity, it only returned 1 & 0. Was this intentional? TheeDeathCaster 2368 — 7y
Ad

Answer this question