GetSoundSpeed: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
(Improve example.)
 
(10 intermediate revisions by 8 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Client function}}
{{Client function}}
This function is used to return the playback speed of the specified [[sound]] element.
This function is used to return the playback speed of the specified [[sound]] [[element]].


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">float getSoundSpeed ( element theSound )</syntaxhighlight>  
<syntaxhighlight lang="lua">float getSoundSpeed ( element theSound )</syntaxhighlight>  
 
{{OOP||[[sound]]:getSpeed|speed|setSoundSpeed}}
===Required Arguments===  
===Required Arguments===  
*'''theSound:''' The [[sound]] element which playback speed you want to return.
*'''theSound:''' the [[sound]] [[element]] which playback speed you want to return.


===Returns===
===Returns===
Returns an [[float]] value indicating the playback speed of the [[sound]] element. Default sound playback speed is '''1.0'''.
Returns an [[float]] value indicating the playback speed of the [[sound]] [[element]]. Default sound playback speed is '''1.0'''.


==Example==  
==Example==  
<section name="Client" class="client" show="true">
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function outputSpeed(soundname)  
function outputSpeed(soundName)  
local sound = playSound("sounds/"..tostring(soundname)..".mp3") --Play the sound from the sounds folder
    if soundName then
setSoundVolume(sound, 0.5) -- set the sound volume to 50%
        local soundElement = playSound("sounds/"..soundName..".mp3") -- Play the sound from the sounds folder
outputChatBox("The sound speed : "..getSoundSpeed(sound)) -- output the sound speed
 
        setSoundSpeed(soundElement, 0.5) -- Set the sound speed to 50%
 
        local soundSpeed = getSoundSpeed(soundElement) -- Get current sound speed
 
        outputChatBox("Sound speed: "..soundSpeed) -- Output the sound speed
    end
end
end
addCommandHandler("soundspeed",outputSpeed)
addCommandHandler("soundspeed", outputSpeed)
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>
Line 26: Line 32:
==See Also==
==See Also==
{{Client_audio_functions}}
{{Client_audio_functions}}
[[hu:getSoundSpeed]]
[[ar:getSoundSpeed]]
[[RO:getSoundSpeed]]
[[PT-BR:getSoundSpeed]]

Latest revision as of 16:00, 21 December 2021

This function is used to return the playback speed of the specified sound element.

Syntax

float getSoundSpeed ( element theSound )

OOP Syntax Help! I don't understand this!

Method: sound:getSpeed(...)
Variable: .speed
Counterpart: setSoundSpeed


Required Arguments

  • theSound: the sound element which playback speed you want to return.

Returns

Returns an float value indicating the playback speed of the sound element. Default sound playback speed is 1.0.

Example

Click to collapse [-]
Client
function outputSpeed(soundName) 
    if soundName then
        local soundElement = playSound("sounds/"..soundName..".mp3") -- Play the sound from the sounds folder

        setSoundSpeed(soundElement, 0.5) -- Set the sound speed to 50%

        local soundSpeed = getSoundSpeed(soundElement) -- Get current sound speed

        outputChatBox("Sound speed: "..soundSpeed) -- Output the sound speed
    end
end
addCommandHandler("soundspeed", outputSpeed)

See Also