sound_replace(index,fname,kind,preload)

Drag & Drop equivalent : GM052

 

index = the name of the resource that is to have it's contents replaced (this is actually the id number, but the resource name represents that number).

fname =The filename of the sound file you want to add.

kind = What type of music you want GM to interpreted it as:

0 - Normal

1 - Background

2 - 3D (positional)

3 - Multimedia Player

preload = indicates whether the sound should immediately be stored in audio memory (true or false).

 

Example #1:

sound_replace(snd_levelmusic,"audio/retrotheme.mp3",0,false)

 

This allows you to replace a single sound resource with multiple sounds by loading them as and when needed off disk. The above example will replace whatever sound is in snd_levelmusic with the sound in the filename "audio/retrotheme.mp3".

 

A good example is a game that has a large number of levels (say 20) and each level has it's own theme tune, if you have 1 sound resource for every level (especially .wav's or .mp3's) the exe will become huge with 20 different pieces of music and could very well prevent dialup people from downloading your game. By using sound_replace you only need 1 sound resource and the music is stored externally and is loaded in as and when which means the music can be downloaded separately.

 

Example #2:

// Depending on the level, load the correct music

if level = 1

{

sound_replace(snd_levelmusic,"audio/retrotheme.mp3",0,false)

}

if level = 2

{

sound_replace(snd_levelmusic,"audio/spookylevel.wav",0,false)

}

if level = 3

{

sound_replace(snd_levelmusic,"audio/jolly.midi",0,false)

}

 

Revision #2