Definition
bool GetSoundPlay(string soundObjectName)
Description
This function returns the sound playback status as a Boolean value of true or false.
Parameters
soundObjectName
Specifies the ambient or 3D sound name. You can also use the name “this” for this parameter. In this case, “this” string refers to the name of the sound to which this script is attached.
Return Value
If the sound is playing, it returns true, otherwise it returns false.
Example 1
sound_play = false message = "" function Init() sound_play = GetSoundPlay("sound1") if sound_play then message = string.format("\nSound is playing") else message = string.format("\nSound isn't playing") end PrintConsole(message) end function Update() end
First, we specify the playback state of “sound1”. Then we display its status in the console using the PrintConsole function.
Example 2
--Name of script is GetSoundPlay2.lua sound_play = false message = "" function Init() sound_play = GetSoundPlay("this") if sound_play then message = string.format("\nSound is playing") else message = string.format("\nSound isn't playing") end PrintConsole(message) end function Update() end
Assume that the above script named GetSoundPlay2.lua is attached to a sound object named “sound1”. In this case, string “this” in the GetSoundPlay function will be equal to “sound1”. In our example, the function GetSoundPlay returns the playback state of the sound “sound1”.
GetSoundPlay