OnResourceReady: Difference between revisions

From GTA Connected
Jump to navigation Jump to search
No edit summary
No edit summary
Line 4: Line 4:
|type = event
|type = event
|games = iii vc sa iv
|games = iii vc sa iv
|desc = when all files are finished downloading to the client, and the resource is ready to start
|desc = when all files are finished downloading to the client. This does NOT include script files.
|arg1 = Resource resource The resource that has entirely loaded.
|arg1 = Resource resource The resource that has entirely loaded.
|note = The [[fadeCamera|fadeCamera]], and [[addEventHandler|addEventHandler]] functions were used in this example. More information on the corresponding pages.
|note = The [[fadeCamera|fadeCamera]], and [[addEventHandler|addEventHandler]] functions were used in this example. More information on the corresponding pages.
|cancel = false
|cancel = false
|notes = This function is only called when extra files (using the <file> tag in meta.xml) are done downloading. The script files (added with <script> tag) are handled differently, so resource might've already started and running before the extra files are downloaded. You can check this in any script file with [[resource.isStarted]].<br>
A good example of this is a resource that shows an image on screen. Such a resource would likely load the image with [[openFile]] and [[graphics.loadPNG]] so these functions should be called in an OnResourceReady event handler. If they're called in an [[OnResourceStart|OnResourceStart]] event handler, it might throw an error since the resource has started, but the image file hasn't been downloaded to the client yet.
|exampleLuaCS = // This example will fade the camera in to show the game world, when the resource is ready.
|exampleLuaCS = // This example will fade the camera in to show the game world, when the resource is ready.



Revision as of 18:53, 22 May 2025

Event Client Only icon-iii.png icon-vc.png icon-sa.png icon-iv.png Online and Offline Not Cancellable

Available since Client 1.0.0

onResourceReady(Event event, Resource resource)

The onResourceReady event is invoked when when all files are finished downloading to the client. This does NOT include script files.

Parameters

1) Event event The event object for this event.
2) Resource resource The resource that has entirely loaded.

Attributes

const This event cannot be cancelled.

Notes

  • The fadeCamera, and addEventHandler functions were used in this example. More information on the corresponding pages.
  • A good example of this is a resource that shows an image on screen. Such a resource would likely load the image with openFile and graphics.loadPNG so these functions should be called in an OnResourceReady event handler. If they're called in an OnResourceStart event handler, it might throw an error since the resource has started, but the image file hasn't been downloaded to the client yet.

Examples

Example 1 - Lua - Client-Side:

// This example will fade the camera in to show the game world, when the resource is ready.

function ResourceReady (event, resource) {
    if(thisResource == resource) {
        game.fadeCamera(0.5, true);
    }
}

Compatibility

There isn't any compatibility information for this event.

Related

Client Related

icon-iii.png icon-vc.png icon-sa.png icon-iv.png OnResourceReady
icon-iii.png icon-vc.png icon-sa.png icon-iv.png OnResourceStart
icon-iii.png icon-vc.png icon-sa.png icon-iv.png OnResourceStop