OnClientGameSoundResult: Difference between revisions
Jump to navigation
Jump to search
Document upcoming 0.1.7 game audio: 11 client APIs, result event, limits and complete dialogue catalog; not a release |
Release 0.1.7 / BUILD199 / Protocol 39: current API availability, setup and improvements |
||
| Line 1: | Line 1: | ||
= onClientGameSoundResult = | = onClientGameSoundResult = | ||
<div style="background:#fff5f5; border:1px solid #d13b3b; border-left:5px solid #d13b3b; color:#111111; padding:0.85rem 1rem; margin:0.75rem 0 1rem;"> | <div style="background:#fff5f5; border:1px solid #d13b3b; border-left:5px solid #d13b3b; color:#111111; padding:0.85rem 1rem; margin:0.75rem 0 1rem;"> | ||
<div style="color:#111111; font-weight:bold; letter-spacing:0.04em;"> | <div style="color:#111111; font-weight:bold; letter-spacing:0.04em;">AVAILABLE SINCE UPDATE 0.1.7</div> | ||
<div style="color:#111111; margin-top:0.25rem;">This event is | <div style="color:#111111; margin-top:0.25rem;">This event is available since G1R:MP 0.1.7.</div> | ||
</div> | </div> | ||
| Line 52: | Line 52: | ||
== Notes == | == Notes == | ||
* | * Available since update 0.1.7. | ||
* See [[Game audio]] for the complete lifecycle and examples. This event is delivered only to the owning client resource. Attach a handler to <code>resourceRoot</code>; no remote event registration is required. | * See [[Game audio]] for the complete lifecycle and examples. This event is delivered only to the owning client resource. Attach a handler to <code>resourceRoot</code>; no remote event registration is required. | ||
* A function returning <code>false</code> did not accept that command and does not generate its own result event. Register handlers before submitting requests. | * A function returning <code>false</code> did not accept that command and does not generate its own result event. Register handlers before submitting requests. | ||
Latest revision as of 23:50, 10 October 2026
onClientGameSoundResult
AVAILABLE SINCE UPDATE 0.1.7
This event is available since G1R:MP 0.1.7.
Reports an asynchronous game audio command result or an observed playback/lifecycle change to the client resource that owns it.
Availability
This event is available in client scripts.
Callback signature
function(requestId, ok, reason, dataJson)
Parameters
| Name | Type | Description |
|---|---|---|
requestId |
number |
Positive request ID returned by a game audio command, or 0 for an unsolicited playback/lifecycle notification. A play request's ID equals its sound handle; control request IDs do not. |
ok |
bool |
Whether this command or notification succeeded. A successful play acknowledgement can still be followed by a playback failure. |
reason |
string |
Empty on ordinary success; otherwise a diagnostic reason such as event-is-2d, native-loading-timeout, native-timeout, playback-not-observed or world-reset. |
dataJson |
string |
JSON text, not a Lua table. Decode with fromJSON. Fields depend on the operation or notification; data.id is the affected sound handle when present. |
Examples
Decode result data, handle session cleanup, and read accumulated sound state:
local sound
addEventHandler("onClientGameSoundResult", resourceRoot,
function(requestId, ok, reason, dataJson)
if requestId == 0 and reason == "world-reset" then
sound = nil
outputDebugString("Game audio session reset")
return
end
local data = fromJSON(dataJson)
if type(data) ~= "table" then return end
if not ok then outputDebugString("Game audio failed: " .. reason) end
if sound and data.id == sound then
local state = getGameSoundState(sound)
if state then outputDebugString("Sound state: " .. state.state) end
end
end)
sound = playSoundFromGame("event:/SFX/UI/SFX_UI_Jingle_LevelUp", {volume = 0.5})
if not sound then outputDebugString("Request rejected before native processing") end
Notes
- Available since update 0.1.7.
- See Game audio for the complete lifecycle and examples. This event is delivered only to the owning client resource. Attach a handler to
resourceRoot; no remote event registration is required. - A function returning
falsedid not accept that command and does not generate its own result event. Register handlers before submitting requests. - An accepted play normally acknowledges
state = "starting",confirmed = false, itsid, key/capability metadata andmode. A play failure suppliesstate = "failed",confirmed = falseandreason, with diagnostic metadata when available. - Preload results contain capability metadata and may have dialogue diagnostics, but do not create a sound handle or contain a sound
id. See getGameSoundInfo. - Volume, pause, position and distance acknowledgements contain
id,operationandaccepted. A successful stop containsid,state = "stopped"andconfirmed. Completed native processing normally also suppliesnativeMs; early rejections, cancellations, timeouts and notifications may omit it. - Unsolicited playback notifications use
requestId = 0and normally containid,state,confirmedandreason. Optional fields can be absent. Decode the payload and use getGameSoundState when accumulated state is needed. - A session reset uses
requestId = 0,ok = false,reason = "world-reset"and an empty JSON object. All current-resource handles, pending requests and cached preload metadata are removed; do not expect a separate result for each cancelled request. - Stopping a still-loading sound can acknowledge its original play with
ok = trueandstate = "stopped". This does not mean playback occurred. Other queued controls for the same sound can fail withcancelled. - Common asynchronous errors include
event-is-2d,event-lookup-not-found,preload-cache-full,sample-load-failed,localized-recording-path-missing,localized-recording-missing,native-start-failed,native-control-failed,sound-not-owned-or-ended,active-sound-limit,owner-limit,native-queue-full,world-not-ready,listener-lost,native-instance-lostandplayback-not-observed. Other detailed native diagnostics can also appear. native-loading-timeoutis the native loading/retry deadline (12 seconds);native-timeoutis the client's command acknowledgement timeout (15 seconds). The latter also cancels a timed-out play request.- Neither
ok,confirmednorrecordingPreparedproves audibility. Observed playback may still be silent due to authored event behavior or the game's audio settings.