Topic api
Sounds API
Functions
sounds:play (name[, sp]) | Plays a sound. |
Objects
SoundGroup | Sound Group. |
SoundGroup (def) | Constructor. |
SoundGroup:count () | Retrieves number of sounds in group. |
SoundGroup:play ([idx[, sp]]) | Plays a sound from the group. |
SoundGroup:get_random () | Retrieves random name from group. |
SoundGroup:get ([idx]) | Retrieves sounds names in group. |
Functions
- sounds:play (name[, sp])
-
Plays a sound.
Parameters:
- name string Sound file without .ogg suffix.
- sp SoundParams Sound parameters. (optional)
Returns:
-
int
Sound handle or
nil
.Usage:
local handle = sounds:play("sound1", {gain=1.0}) if handle then print("Sound handle: " .. handle) end
Objects
- SoundGroup
-
Sound Group.
Fields:
- count SoundGroup:count Retrieves number of available sounds.
- play SoundGroup:play Plays indexed or random sound.
- no_prepend
bool
If set to
true
, omits prepending "sounds_" to sound filenames when played.
- SoundGroup (def)
-
Constructor.
Parameters:
- def table Sound definition.
Returns:
-
SoundGroup
Sound group definition table.
Usage:
-- create new sound groups local s_group1 = SoundGroup({"sound1", "sound2"}) local s_group2 = SoundGroup({"modname_sound1", "modname_sound2", no_prepend=true}) -- play sound at index s_group1:play(2) -- play random sound from group s_group1:play() -- play sound at index with parameters s_group1:play(1, {gain=1.0, max_hear_distance=100}) -- play random sound with parameters s_group1:play({gain=1.0, max_hear_distance=100}) -- calling a SoundGroup instance directly is the same as executing the "play" method s_group(1, {gain=1.0, max_hear_distance=100})
- SoundGroup:count ()
-
Retrieves number of sounds in group.
Returns:
-
int
- SoundGroup:play ([idx[, sp]])
-
Plays a sound from the group.
If idx is not specified, an available sound will be selected randomly from the group.
Notes:
- idx & sp parameters positions can be switched.
Parameters:
- idx int Sound index. (optional)
- sp SoundParams Sound parameters. (optional)
Returns:
-
int
Sound handle or
nil
.Usage:
local handle = SoundGroup:play(2, {gain=1.0}) if handle then print("Sound handle: " .. handle) end
- SoundGroup:get_random ()
-
Retrieves random name from group.
Returns:
- SoundGroup:get ([idx])
-
Retrieves sounds names in group.
If
idx
is supplied, a string ornil
is returned. If there is only one sound in the group, the string name of that sound is returned. Otherwise, a table is returned with all sound file names.Parameters:
- idx int Sound index. (optional)
Returns: