Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: actaria on Thu 07/03/2024 16:10:16

Title: [SOLVED] Changing rooms without the music starting over
Post by: actaria on Thu 07/03/2024 16:10:16
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) Select
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) Select
import bool IsAudioClipPlaying(AudioClip* clip);


And finally in my room i have:
Code (ags) Select
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) Select
bool IsAudioClipPlaying(AudioClip* clip)


Can you please help me if you can see the mistake i made.
Thank you very much.
Title: Re: Changing rooms without the music starting over
Post by: Crimson Wizard on Thu 07/03/2024 17:21:15
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.
Title: Re: Changing rooms without the music starting over
Post by: actaria on Thu 07/03/2024 20:42:58
Hello Crimson Wizard,
I did what you said and now it's perfectly working 👍

Once again thank you very much for your help
Title: Re: [SOLVED] Changing rooms without the music starting over
Post by: Khris on Fri 08/03/2024 08:32:12
You can also take a look at this:
https://www.adventuregamestudio.co.uk/forums/beginners-technical-questions/musicplayer/msg636660568/#msg636660568
(set up multiple tracks and have them play in specific rooms without restarting)
Title: Re: [SOLVED] Changing rooms without the music starting over
Post by: actaria on Fri 08/03/2024 13:24:55
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