Difference between revisions of "minetest.sound play"

From Minetest Developer Wiki
Jump to navigation Jump to search
(Created page with "{{DISPLAYTITLE:minetest.sound_play}} == Syntax == <source>minetest.sound_play(spec, sound parameters)</source> {{Stub}} Category:Methods")
 
Line 1: Line 1:
 
{{DISPLAYTITLE:minetest.sound_play}}
 
{{DISPLAYTITLE:minetest.sound_play}}
 
== Syntax ==
 
== Syntax ==
<source>minetest.sound_play(spec, sound parameters)</source>
+
<source>minetest.sound_play(SimpleSoundSpec, SoundParameters)</source>
  
{{Stub}}
+
== Description ==
 +
Plays a sound.
 +
 
 +
<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
 +
* <code>loop = bool</code>: Sound is looped
 +
The location can be specified with one of the following fields (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 hanlder that can be passed to <source enclose=none>minetest.sound_stop(handle)</source> to stop the sound.
 +
 
 +
{{MissingExample}}
  
 
[[Category:Methods]]
 
[[Category:Methods]]

Revision as of 14:08, 19 January 2013

Syntax

minetest.sound_play(SimpleSoundSpec, SoundParameters)

Description

Plays a sound.

SimpleSoundSpec can be a string with the filename (without the file extention) or a table with the fields name="name" and gain=float.

SoundParameters is a table with the following fields:

  • gain = float: the gain (default 1.0)
  • max_hear_distance = int: the maximum hear distance
  • loop = bool: Sound is looped

The location can be specified with one of the following fields (if none is used, its played locationless to all players):

  • to_player = "playername": Sound is played locationless to the player
  • pos = position: Sound is played at this position
  • object = ObjectRef: Sound is played connected to the object

The function returns a sound hanlder that can be passed to minetest.sound_stop(handle) to stop the sound.

Mbox information.png This article is missing examples.
Feel free to add them.