IsSoundLooped: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(add isSoundLooped)
 
(Remove obsolete Requirements section)
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Client function}}
{{Client function}}
{{New feature/item|3.0160|1.5.8|20785|This function is used to return the current loop option of the [[sound]] [[element]].}}
{{Added feature/item|1.5.9|1.5.8|20785|This function is used to return the current loop state of the [[sound]] [[element]].}}


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">bool isSoundLooped(element theSound)</syntaxhighlight>  
<syntaxhighlight lang="lua">bool isSoundLooped ( element theSound )</syntaxhighlight>  
{{OOP||[[sound]]:isLooped||setSoundLooped}}
{{OOP||[[sound]]:isLooped||setSoundLooped}}
===Required Arguments===  
===Required Arguments===  
Line 10: Line 10:


===Returns===
===Returns===
Returns ''true'' if the [[sound]] [[element]] is seted to loop, ''false'' otherwise.
Returns ''true'' if the [[sound]] [[element]] is looped, ''false'' otherwise.


==Example==
This will create a [[sound]] [[element]] and change its state to looped, with a command to switch the loop state and output its state:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local mySound
local mySound
addEventHandler('onClientResourceStart', resourceRoot, function()
 
     mySound = playSound('sound.mp3')
addEventHandler ("onClientResourceStart", resourceRoot, function ()
     setSoundLooped(mySound, true)
     mySound = playSound ("sound.mp3")
     setSoundLooped (mySound, true)
end)
end)


addCommandHandler('loop', function()
addCommandHandler ("loop", function ()
     if isElement(mySound) then
     if isElement (mySound) then
         local newState = not isSoundLooped(mySound)
         local newState = not isSoundLooped (mySound)
         setSoundLooped(mySound, newState)
         setSoundLooped (mySound, newState)
 
         if newState then
         if newState then
             outputChatBox('The sound will loop...')
             outputChatBox ("The sound will loop!")
         else
         else
             outputChatBox('The sound will not loop anymore...')
             outputChatBox ("The sound will not loop anymore!")
         end
         end
     end
     end

Latest revision as of 17:24, 7 November 2024

This function is used to return the current loop state of the sound element.

Syntax

bool isSoundLooped ( element theSound )

OOP Syntax Help! I don't understand this!

Method: sound:isLooped(...)
Counterpart: setSoundLooped


Required Arguments

  • theSound: The sound element which you want to get the loop state.

Returns

Returns true if the sound element is looped, false otherwise.

Example

This will create a sound element and change its state to looped, with a command to switch the loop state and output its state:

local mySound

addEventHandler ("onClientResourceStart", resourceRoot, function ()
    mySound = playSound ("sound.mp3")
    setSoundLooped (mySound, true)
end)

addCommandHandler ("loop", function ()
    if isElement (mySound) then
        local newState = not isSoundLooped (mySound)
        setSoundLooped (mySound, newState)

        if newState then
            outputChatBox ("The sound will loop!")
        else
            outputChatBox ("The sound will not loop anymore!")
        end
    end
end)

See Also