Preload (Method): Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Quenty
No edit summary
>Quenty
No edit summary
(No difference)

Revision as of 22:31, 11 July 2011

Preload( string asset )
Returns nil
Description: Downloads the requested asset to the client and prepares it for use.
Member of: ContentProvider


WARNING: This feature only effectively works in Local scripts.


Example
Can be used to load an asset (common assets loaded are images) so it doesn't take any time when shown as textures or decals.
Game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id=2453543")



Example
A fast way to load assets is to put them into a table, then loop through the table, and load them.
Assets = {2253543,2434541,5133543,2423433,41143243,2453865,21433365,2154549}

for i=1, #Assets do
Game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id="..Assets[i])
end

The script will wait until the assets are loaded, then go on. Thus, you can make loading bars using GUIs by changing the scale of a GUI from 0 to 1.

Assets = {2253543,2434541,5133543,2423433,41143243,2453865,21433365,2154549}
NumOf = 0

for i=1, #Assets do
Game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id="..Assets[i])
NumOf = NumOf + 1
script.Parent.GUI.LoadingBar.Bar.Size = UDim2.new(NumOf/#Assets, 0, 1, 0)
end

This way, it ads NumOf each time it uploads a new thing, then calculates how the loading bar should look. The LoadingBar would be sized so it that it would look like the full bar, then the actual 'Bar' would move along with the amount that was done.