Globals::waitAsync: Difference between revisions

From RAGE Multiplayer Wiki
(Created page with "__NOTOC__ {{ClientsideJsFunction}} An asynchronous function that pauses execution of your current script. {{JSContainer| == Syntax == <pre> mp.game.wait(ms); </pre> === Par...")
 
No edit summary
 
Line 7: Line 7:


<pre>
<pre>
mp.game.wait(ms);
mp.game.waitAsync(ms);
</pre>
</pre>


Line 14: Line 14:


== Examples ==
== Examples ==
Pauses the script for 10ms before checking again if ped.handle is still 0 or not and unfreezes the ped when it's created with a valid handle.
Requests the specified scaleform, waits until it is loaded then returns the scaleform handle.
 
{{ClientsideCode|
<pre>
<pre>
let ped = mp.peds.new();
async function requestScaleform(scaleformName) {
while (ped.handle === 0) await mp.game.waitAsync(0);
    const handle = mp.game.graphics.requestScaleformMovie(scaleformName);
ped.freezePosition(false);
 
    while (!mp.game.graphics.hasScaleformMovieLoaded(handle)) {
        await mp.game.waitAsync(0);
    }
 
    return handle;
}
</pre>
</pre>
}}
}}
}}


== See Also ==
== See Also ==
{{GameGlobals}}
{{GameGlobals}}

Latest revision as of 06:37, 18 August 2020

Client-Side
Function

 JavaScript



An asynchronous function that pauses execution of your current script.

JavaScript Syntax

Syntax

mp.game.waitAsync(ms);

Parameters

  • ms: Int

Examples

Requests the specified scaleform, waits until it is loaded then returns the scaleform handle.

Client-Side
async function requestScaleform(scaleformName) {
    const handle = mp.game.graphics.requestScaleformMovie(scaleformName);

    while (!mp.game.graphics.hasScaleformMovieLoaded(handle)) {
        await mp.game.waitAsync(0);
    }

    return handle;
}


See Also