GetSoundVolume

Definition

double GetSoundVolume(string soundObjectName)

Description

This function returns the volume of ambient or 3D sound soundObjectName.

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

Volume of 3D or ambient sound.

Example 1

volume = 0.0

function Init()
    volume = GetSoundVolume("sound1")

    message = string.format("\nSound volume is > %.2f", volume)
    PrintConsole(message)
end

function Update()

end
First, we get the volume of sound “sound1”. Then we display it in the console using the PrintConsole function.

Example 2

--Name of script is GetSoundVolume2.lua

volume = 0.0

function Init()
    volume = GetSoundVolume("this")

    message = string.format("\nSound volume is > %.2f", volume)
    PrintConsole(message)
end

function Update()

end
Assume that the above script named GetSoundVolume2.lua is attached to a sound object named “sound1”. In this case, string “this”  in the GetSoundVolume function will be equal to “sound1”. In our example, the function GetSoundVolume returns the volume of current sound, which is “sound1”.
adminGetSoundVolume