Meteor 2 Scripting Functions
Audio
void preloadSound(string soundName)
Preload a sound effect.
void onWorldStart()
{
preloadSound("ambience\\City_A");
}
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).
void preloadSoundNumber(int soundNumber)
Preload a sound effect number.
void onWorldStart()
{
int soundNumber = getSoudNumber("ambience\\City_A")
preloadSoundNumber(soundNumber);
}
Sound effects are loaded as needed and cleared at the start of each level.
Preloading larger effects can reduce spikes while playing a map.
void playSound(string soundName)
Play a sound locally without spatialisation.
playSound("world\\battle");
Numbers are not required on the end of the effect name as multiple files with the same number are randomised (same effect).
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).
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");
}
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).
void playSoundDelayed(string soundName, float delayInSeconds, bool broadcast=false)
Play a sound locally without spatialisation after a specified delay in seconds.
playSoundDelayed("world\\battle", 2);
void playSound2D(vector2 pos, string soundName, bool broadcast=false)
Play a one shot sound from a 2D position.
playSound2D(getPos(PLAYER_OBJECT), "world\\battle");
broadcast works for server and clients.
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).
int soundNumber = getSoundNumber("world\\battle");
if(soundNumber != -1)
playSoundNumber2D(getPos(PLAYER_OBJECT), soundNumber, "");
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).
bool isSoundInstancePlaying(string instanceTag)
Determine if a sound instance is playing.
float getSoundInstanceGain(string instanceTag)
Get the gain (volume) of a playing sound instance.
void setSoundInstanceGain(string instanceTag, float gain)
Set the gain (volume) of a playing sound instance.
void getSoundNumber(string effectName)
Get a sound number from a sound effect name.
int soundNumber = getSoundNumber("world\\battle");
print(soundNumber);
Returns -1 if the sound effect does not exist.
void playMusic(string musicFileName)
Play music from file.
playMusic("1996.mod");
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.
float getMusicPos()
Get the currently playing music position in seconds.
print(getMusicPos())
void setMusicPos(float seconds)
Seek the currently playing music to the current position in seconds.
setMusicPos(30);
string getMusicFilename()
Get the currently playing music filename.
print(getMusicFilename())
void stopMusic()
Stop music playing.
stopMusic();
Music is stopped and cannot be resumed (use playMusic to play more music).
Music will not resume until a new level is started.
void restartMusic()
Rewind currently playing music to the start.
restartMusic();
void pauseMusic()
Pause currently playing music.
pauseMusic();
void resumeMusic()
Resume current music.
resumeMusic();
void isMusicPaused()
Is music paused?
if(isMusicPaused())
{
print("Music is paused");
}
else
{
print("Music is not paused");
}
Index