Sound
Represents a sound that can be played
Obtained by indexing the SoundAPI
Exists as an object-oriented alternative to sounds:playSound()
For the purposes of the examples assume:
local mySound = sounds["entity.bat.ambient"]
stop()
Stops the sound
Example:
mySound:stop()
play()
Plays the sound
Example:
mySound:play()
pause()
Pauses the sound
Example:
mySound:pause()
setPos(Vector3)
Sets the position of the sound
Example:
mySound:setPos(player:getPos())
getPos()
Gets the position of the sound as set by setPos
Example:
mySound:getPos()
isPlaying()
Gets if the sound is playing, but this is an unreliable function. A workaround is to stop the sound before you play it (even if it isn't playing) so you can reset the playing state.
This function is unreliable and may not work as intended. A usable workaround is to stop the sound before you play it (even if it isn't playing) so you can reset the playing state.
Example:
mySound:isPlaying()
setVolume(number)
Sets the volume of the sound
Example:
mySound:setVolume(5)
getVolume()
Gets the volume of the sound
Example:
mySound:getVolume()
setPitch(number)
Sets the pitch of the sound
Example:
mySound:setPitch(5)
getPitch()
Gets the pitch of the sound
Example:
mySound:getPitch()
setLoop(bool)
Sets if the sound will loop or not
Example:
mySound:setLoop(true)
isLooping()
Gets if the sound is set to loop or not
Example:
mySound:isLooping()
setAttenuation(number)
Sets the attenuation of the sound
Example:
mySound:setAttenuation(5)
getAttenuation()
Gets the attenuation of the sound
Example:
mySound:getAttenuation()
setSubtitle(string)
Sets the subtitle (the name that Minecraft's subtitle function will call the sound)
Example:
mySound:setSubtitle("Bat ecolocates")
getSubtitle()
Gets the subtitle
Example:
mySound:getSubtitle()