Difference between revisions of "minetest.sound play"

From Minetest Developer Wiki
Jump to navigation Jump to search
 
(19 intermediate revisions by 7 users not shown)
Line 1: Line 1:
 +
{{UnofficialLua}}
 
{{DISPLAYTITLE:minetest.sound_play}}
 
{{DISPLAYTITLE:minetest.sound_play}}
== Syntax ==
+
See [https://minetest.gitlab.io/minetest/minetest-namespace-reference/#sounds minetest.sound_play] in the Lua API documentation, and [https://minetest.gitlab.io/minetest/sounds/ Sounds] for general information about sound parameters.
<source>minetest.sound_play(SimpleSoundSpec, SoundParameters)</source>
 
  
== Description ==
+
[[Category:Methods|s]]
Plays a sound.
 
 
 
Only OGG files are supported. For positional playing of sounds, only single-channel (mono) files are supported. Otherwise OpenAL will play them non-positionally.
 
 
 
<code>SimpleSoundSpec</code> can be a string with the filename (without the file extention) or a table with the fields <code>name="name"</code> and <code>gain=float</code>.
 
 
 
<code>SoundParameters</code> is a table with the following fields:
 
* <code>gain = float</code>: the gain. default = 1.0
 
* <code>max_hear_distance = int</code>: the maximum hear distance. default = 32
 
* <code>loop = bool</code>: Sound is looped. Only sounds connected to objects can be looped. default = false
 
 
 
The location can be specified with one of the following fields in the SoundParameters (if none is used, its played locationless to all players):
 
* <code>to_player = "playername"</code>: Sound is played locationless to the player
 
* <code>pos = [[position]]</code>: Sound is played at this position
 
* <code>object = [[ObjectRef]]</code>: Sound is played connected to the object
 
 
 
The function returns a sound handle that can be passed to <source enclose=none>minetest.sound_stop(handle)</source> to stop the sound.
 
 
 
== Examples ==
 
<source>
 
minetest.sound_play("testmod_testsound", {
 
pos = {x=0, y=0, z=0},
 
max_hear_distance = 100,
 
gain = 10.0,
 
})
 
</source>
 
Plays the sound <code>testmod_testsound.ogg</code> at the postion 0,0,0.
 
 
 
[[Category:Methods]]
 

Latest revision as of 13:50, 25 October 2022

Mbox warning.png This page contains unofficial, low-quality Lua API documentation and is likely to be outdated or wrong. Do not rely on it!
For the official and up-to-date documentation, see Lua API Documentation.
Mbox warning.png This page has been proposed for deletion for the following reason: "Contains unofficial and potentially outdated, redundant and inconsistent Lua API information"
If you don't think that this page should be deleted, please explain why on the talk page.

See minetest.sound_play in the Lua API documentation, and Sounds for general information about sound parameters.