Meteor 2 Scripting Functions
Audio
void preloadSound(string soundName)
Preload a sound effect.

Example
void onWorldStart()
{
    preloadSound("ambience\\City_A");
}

Comments
Sound effects are loaded as needed and cleared at the start of each level.
Preloading larger effects can reduce spikes while playing a map.
Numbers are not required on the end of the effect name as multiple files with the same number are randomised (same effect).

See also
preloadSoundNumber

void preloadSoundNumber(int soundNumber)
Preload a sound effect number.

Example
void onWorldStart()
{
    int soundNumber = getSoudNumber("ambience\\City_A")
    preloadSoundNumber(soundNumber);
}

Comments
Sound effects are loaded as needed and cleared at the start of each level.
Preloading larger effects can reduce spikes while playing a map.

See also
preloadSound

void playSound(string soundName)
Play a sound locally without spatialisation.

Example
playSound("world\\battle");

Comments
Numbers are not required on the end of the effect name as multiple files with the same number are randomised (same effect).

See also
playSoundDelayed playSound2D

void playSoundNumber(int soundNumber, bool loop=false, string instanceTag="", float gain=1.0, float pitch=1.0)
Play a sound by number (faster) locally without spatialisation and support instanceTag (looping).

Example
int rainSoundNumber = -1;

void storeSoundNumbers()
{
    rainSoundNumber = getSoundNumber("ambience\\Rain_A");
}

void onWorldStart()
{
    storeSoundNumbers();
}

void onGameLoad()
{
    storeSoundNumbers();
}

void onUpdate(float deltaTime)
{
    playSoundNumber(rainSoundNumber, true, "RAIN_LOOP");
}

Comments
Pass loop as false to play a one shot sound.
Set loop to true and call playSoundNumber with same intanceTag every frame to keep playing a loop (stop calling to stop the sound).

See also
playSound playSoundDelayed playSound2D playSoundNumber2D getSoundNumber

void playSoundDelayed(string soundName, float delayInSeconds, bool broadcast=false)
Play a sound locally without spatialisation after a specified delay in seconds.

Example
// play sound after 2 seconds
playSoundDelayed("world\\battle", 2);

See also
playSound playSound2D

void playSound2D(vector2 pos, string soundName, bool broadcast=false)
Play a one shot sound from a 2D position.

Example
playSound2D(getPos(PLAYER_OBJECT), "world\\battle");

Comments
broadcast works for server and clients.

See also
playSound playSoundNumber2D

void playSoundNumber2D(vector2 pos, int soundNumber, bool loop=false, string instanceTag="", float gain=1.0, float pitch=1.0, bool broadcast=false)
Play a sound by number (faster) from a 2D position and support instanceID (looping).

Example
int soundNumber = getSoundNumber("world\\battle");
if(soundNumber != -1)
    playSoundNumber2D(getPos(PLAYER_OBJECT), soundNumber, "");

Comments
broadcast works for server and clients but does not support looped sounds.
Set loop to false to play a one shot sound.
Set loop to true and call playSoundNumber2D with same intanceTag every frame to keep playing a loop (stop calling to stop the sound).

See also
getSoundNumber playSound playSoundNumber playSound2D

bool isSoundInstancePlaying(string instanceTag)
Determine if a sound instance is playing.

See also
getSoundInstanceGain setSoundInstanceGain

float getSoundInstanceGain(string instanceTag)
Get the gain (volume) of a playing sound instance.

See also
setSoundInstanceGain isSoundInstancePlaying

void setSoundInstanceGain(string instanceTag, float gain)
Set the gain (volume) of a playing sound instance.

See also
getSoundInstanceGain isSoundInstancePlaying

void getSoundNumber(string effectName)
Get a sound number from a sound effect name.

Example
int soundNumber = getSoundNumber("world\\battle");
print(soundNumber);

Comments
Returns -1 if the sound effect does not exist.

See also
getSoundNumber playSound playSound2D

void playMusic(string musicFileName)
Play music from file.

Example
playMusic("1996.mod");

Comments
Pass a filename only to search in base\music.
Pass an absolute path to play from another location.
Supported formats include Ogg Vorbis, MOD, S3M, XM.

See also
stopMusic restartMusic getMusicFilename setMusicPos

float getMusicPos()
Get the currently playing music position in seconds.

Example
print(getMusicPos())

See also
setMusicPos

void setMusicPos(float seconds)
Seek the currently playing music to the current position in seconds.

Example
// jump to 30 seconds in
setMusicPos(30);

See also
getMusicPos

string getMusicFilename()
Get the currently playing music filename.

Example
print(getMusicFilename())

See also
playMusic

void stopMusic()
Stop music playing.

Example
stopMusic();

Comments
Music is stopped and cannot be resumed (use playMusic to play more music).
Music will not resume until a new level is started.

See also
playMusic restartMusic

void restartMusic()
Rewind currently playing music to the start.

Example
restartMusic();

See also
playMusic stopMusic

void pauseMusic()
Pause currently playing music.

Example
pauseMusic();

See also
resumeMusic isMusicPaused

void resumeMusic()
Resume current music.

Example
resumeMusic();

See also
resumeMusic isMusicPaused

void isMusicPaused()
Is music paused?

Example
if(isMusicPaused())
{
    print("Music is paused");
}
else
{
    print("Music is not paused");
}

See also
pauseMusic resumeMusic


Index