Quote from: slasher on Fri 20/03/2015 13:13:17...this works for me:
In Global asc:Code: ags function on_event (EventType event, int data) { AudioChannel *bgm; void SetBGM(AudioClip *music) { if (bgm != null && bgm.PlayingClip == music) return; // don't if music is already playing bgm = music.Play(); } }
No it doesn't. AGS does not support nested functions, which is exactly what you've posted here. You're also (making an attempt at) "calling" this nested function every single time any event (that is handled by on_event, of course) occurs. Your nested function also would never do anything as you are creating a pointer (which defaults to null) immediately before checking that it is not null. Here's an amended version of what you were trying to suggest (for posterity's sake):
AudioChannel *bgm;
void SetBGM(AudioClip *music)
{
if (bgm != null && bgm.PlayingClip == music) return; // don't play the music if it's already playing
bgm = music.Play();
}
function on_event (EventType event, int data)
{
if (event == eEventEnterRoomBeforeFadein)
{
SetBGM(aMusicName);
}
}