Topic general
General Sounds
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 ([idx]) | Retrieves sounds names in group. |
Pre-defined Sound Groups
sounds.bird | Bird sounds. |
sounds.bite | Bite sounds. |
sounds.bounce | Bounce sounds. |
sounds.cat_meow | Cat meow sounds. |
sounds.coin | Coin sounds. |
sounds.cow_moo | Cow moo sounds. |
sounds.dog_bark | Dog bark sounds. |
sounds.elephant | Elephant sounds. |
sounds.entity_hit | Entity hit sounds. |
sounds.explosion | Explosion sounds. |
sounds.frog | Frog sounds. |
sounds.fuse | Fuse sounds. |
sounds.gallop | Gallop sounds. |
sounds.horse_neigh | Horse neigh sounds. |
sounds.horse_snort | Horse snort sounds. |
sounds.horse | Horse sounds. |
sounds.pencil | Pencil sounds. |
sounds.quail | Quail sounds. |
sounds.rooster | Rooster sounds. |
sounds.sheep | Sheep sounds. |
sounds.skeleton | Skeleton sounds. |
Functions
- sounds:play (name[, sp])
-
Plays a sound.
Parameters:
- name string Sound file without .ogg suffix.
- sp SoundParams Sound parameters. (optional)
Returns:
-
list
bool
true if sound played &int
sound handle.Usage:
local ret, handle = sounds:play("sound1", {gain=1.0}) if ret 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:
-
list
bool
true if sound played &int
sound handle.Usage:
local ret, handle = SoundGroup:play(2, {gain=1.0}) if ret then print("Sound handle: " .. handle) end
- 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:
Pre-defined Sound Groups
- sounds.bird
-
Bird sounds.
Sounds:
- bird_01
- bird_02
- bird_03
- sounds.bite
-
Bite sounds.
Sounds:
- apple_bite
- sounds.bounce
-
Bounce sounds.
Sounds:
- boing
- sounds.cat_meow
-
Cat meow sounds.
Sounds:
- cat_meow
- sounds.coin
-
Coin sounds.
Sounds:
- coin
- sounds.cow_moo
-
Cow moo sounds.
Sounds:
- cow_moo_01
- cow_moo_02
- sounds.dog_bark
-
Dog bark sounds.
Sounds:
- dog_bark
- sounds.elephant
-
Elephant sounds.
Sounds:
- elephant
- sounds.entity_hit
-
Entity hit sounds.
Sounds:
- entity_hit
- sounds.explosion
-
Explosion sounds.
Sounds:
- explosion
- sounds.frog
-
Frog sounds.
Sounds:
- frog
- sounds.fuse
-
Fuse sounds.
Sounds:
- fuse
- sounds.gallop
-
Gallop sounds.
Sounds:
- gallop_01
- gallop_02
- sounds.horse_neigh
-
Horse neigh sounds.
Sounds:
- horse_neigh_01
- horse_neigh_02
- sounds.horse_snort
-
Horse snort sounds.
Sounds:
- horse_snort_01
- horse_snort_02
- sounds.horse
-
Horse sounds.
Includes sounds from sounds.horse_neigh & sounds.horse_snort.
- sounds.pencil
-
Pencil sounds.
Sounds:
- pencil_erase
- pencil_write
- sounds.quail
-
Quail sounds.
Sounds:
- quail
- sounds.rooster
-
Rooster sounds.
Sounds:
- rooster
- sounds.sheep
-
Sheep sounds.
Sounds:
- sheep
- sounds.skeleton
-
Skeleton sounds.
Sounds:
- skeleton_bones