Meteor 2 Scripting Functions
Audio
void playSound(string soundName)
Play a sound locally without spatialisation.

Example
playSound("world\\battle");

See also
playSoundDelayed playSound2D

void playSoundNumber(string soundName, instanceID soundName)
Play a sound by number (faster) locally without spatialisation and support instanceID (looping).

Example
int rainSoundNumber = -1;

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

void onWorldsStart()
{
    storeSoundNumbers();
}

void onGameLoad()
{
    storeSoundNumbers();
}

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

Comments
Pass instanceID as "" to play a one shot sound.
Pass instanceID as a unique string and call playSoundNumber every frame to play a loop (stop calling to stop the sound).

See also
playSound playSoundDelayed playSound2D playSoundNumber2D getSoundNumber

void playSoundDelayed(string soundName, float delayInSeconds)
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)
Play a one shot sound from a 2D position.

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

Comments
If run from the server the sound is also played on all clients.
If run from a client the sound is local only.

See also
playSound playSoundNumber2D

void playSoundNumber2D(vector2 pos, int soundNumber, string instanceID)
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
If run from the server the sound is also played on all clients.
If run from a client the sound is local only.
Pass instanceID as "" to play a one shot sound.
Pass instanceID as a unique string and call playSoundNumber2D every frame to play a loop (stop calling to stop the sound).

See also
getSoundNumber playSound playSoundNumber playSound2D

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

Generated on the 24 June 2024 at 06:55:35 (UK Time)