[SOLVED] Changing rooms without the music starting over

Started by actaria, Thu 07/03/2024 16:10:16

Previous topic - Next topic

actaria

Hello,
It's already me again 😀
I am trying to improve a few things and now i on the sounds, musics parts.
Until now i was doing little tricks here and there to prevent music to start over again when reentering a room before the end of the music.
I found a thread on the forum here:
https://www.adventuregamestudio.co.uk/forums/beginners-technical-questions/changing-rooms-without-the-music-starting-over/

I am trying to use the 2nd method with audio channels

In GlobalScipt.asc i have:

Code: ags
function game_start()
{
 bool IsAudioClipPlaying(AudioClip* clip)
{
    for (int i = 0; i < System.AudioChannelCount; i++)
    {
        if (System.AudioChannels[i].PlayingClip == clip)
        {
            return true; // found it
        }
    }
    return false; // nowhere
 }
}

In GlobalScript.ash i have:
Code: ags
import bool IsAudioClipPlaying(AudioClip* clip);


And finally in my room i have:
Code: ags
function room_AfterFadeIn()
{
    if (!IsAudioClipPlaying(aMusic1))
    {
        aMusic1.Play();
    }
}


Unfortunately it gives an error in the GlobalScript.asc

"GlobalScript.asc(13): Error (line 13): Nested functions not supported (you may have forgotten a closing brace)"
this is this line:
Code: ags
 bool IsAudioClipPlaying(AudioClip* clip)


Can you please help me if you can see the mistake i made.
Thank you very much.

Crimson Wizard

Quote from: actaria on Thu 07/03/2024 16:10:16Unfortunately it gives an error in the GlobalScript.asc

"GlobalScript.asc(13): Error (line 13): Nested functions not supported (you may have forgotten a closing brace)"

You put function IsAudioClipPlaying inside game_start. Put them separately instead.

actaria

Hello Crimson Wizard,
I did what you said and now it's perfectly working 👍

Once again thank you very much for your help

Khris


actaria

Hello Khris,
Playing tracks in specific room without restarting, this is really interesting !
I will have a look tonight, thank you for the link.

EDIT:
Couldn't resist to have a look at your link even if i am at work 😀  and i like it, it seems to be easy to  use.
I will try your module as soon as i get home

SMF spam blocked by CleanTalk