Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Alexander Hillebrand on Wed 21/01/2015 14:29:17

Title: No background music
Post by: Alexander Hillebrand on Wed 21/01/2015 14:29:17
I've got a problem getting music in to my game.
I'm using the latest version of AGS (version 3.3.2). In order to get my background music working, I imported the music (OGG-file) in the Music folder (afer renaming it into "Music1.ogg")
After searching in the forums I found the following code:

    function room_RepExec()
    {
         aMusic1.Play();
    }
but it didn't work. In the properties pane of the music file i've activated "repeating" to "True", set the volume to "100", but still no music.
I've also tried

    function Room_AfterFadeIn()
    {
         aMusic1.Play();
    }

Did I make a mistake or is one of the functions changed?
Title: Re: No background music
Post by: Crimson Wizard on Wed 21/01/2015 14:46:36
This code:
Code (ags) Select

function room_RepExec()
{
     aMusic1.Play();
}

-- is terrible, never do such things. RepExec repeats same commands with default frequency of 40 times per second, so you would be restarting same music over and over again 40 times per second.
You need to remove this command from RepExec (unless you already did that).

This should work properly, though:
Code (ags) Select

function Room_AfterFadeIn()
{
    aMusic1.Play();
}
Title: Re: No background music
Post by: NickyNyce on Wed 21/01/2015 14:51:49
If what the wizard says, doesn't work, try renaming your music to..aMusic1

I'm not using 3.3.2, so maybe things are a bit different. I've only used wav files, but make sure the music name matches your scripting name.

Title: Re: No background music
Post by: Alexander Hillebrand on Wed 21/01/2015 15:23:15
Thanks for the quick answers, unfortunately, it still doesn't work. Some of these days I guess. I'm finishing the game now without music, the only option left. Thanks anyway for the help!
Title: Re: No background music
Post by: Crimson Wizard on Wed 21/01/2015 15:39:01
Wait a moment... were you renaming FILE?

Since AGS 3.2.0 the file name and location are not important, at all. Instead, you import the music in project tree in the Editor and use the script name you gave it, regardless of file name.

You said it did not work... do you mean that music does not play, or you get compiler errors?
Title: Re: No background music
Post by: Alexander Hillebrand on Wed 21/01/2015 15:41:49
No music playing at all. But also no compile errors, kind of weird isn't it?
Title: Re: No background music
Post by: Cassiebsg on Wed 21/01/2015 15:49:05
Like CW said, are you sure you have loaded your music file in the project tree?

You need to look at your explore project, then open Audio, then right click the music "folder" and add audio file(s)... choose your file.
Then try and rename the ScriptName to aMusic1 (file name does not matter what is called!).

This worked for me when I added mp3 music to my game, so it should also work for you...

You can also add the code to room_Load... just remember to add/link the function in your room properties event...

PS - Once your music is loaded you can used the play button to listen to it, if it works there then it should also work in game.
Title: Re: No background music
Post by: Crimson Wizard on Wed 21/01/2015 15:52:03
Cassiebsg, if he did not have aMusic1 in his project tree, his script won't compile.
Title: Re: No background music
Post by: Cassiebsg on Wed 21/01/2015 15:54:33
Ah, okay. Didn't knew that. :-[

Then maybe it's an event link missing?
Title: Re: No background music
Post by: Crimson Wizard on Wed 21/01/2015 15:56:55
Quote from: Cassiebsg on Wed 21/01/2015 15:54:33
Then maybe it's an event link missing?

Yes, BTW, Alexander Hillebrand, is your Room_AfterFadeIn function connected to actual event?
Open Room property pane and see if the function name is in its place there.
In sake of the test you can also add Display command, like:
Code (ags) Select

function Room_AfterFadeIn()
{
    aMusic1.Play();
    Display("Music should start playing now");
}
Title: Re: No background music
Post by: Alexander Hillebrand on Wed 21/01/2015 17:10:10
Okay I got it: In order to get music in a room (in this case the very first one) I have to make a property in the property-pane. Is that something like "MusicOnLoad'and than set it to "1" or something like that?
Title: Re: No background music
Post by: Crimson Wizard on Wed 21/01/2015 17:40:18
Quote from: Alexander Hillebrand on Wed 21/01/2015 17:10:10
Okay I got it: In order to get music in a room (in this case the very first one) I have to make a property in the property-pane. Is that something like "MusicOnLoad'and than set it to "1" or something like that?
No, it is the obsolete information, refering to old versions of AGS.

Did you check our suggestion from previous posts, the one about event connection?
Title: Re: No background music
Post by: Mr Games on Mon 12/11/2018 14:15:39
Apologies for reviving this thread from the dead, but I have the exact same issue.

Latest version of AGS,
My code for room1 is

function Room_AfterFadeIn ()
{
aMusic1.Play(1);
}

I also tested this after adding the following to connect it to an event, as was suggested:
Display("Music should be playing now");

In properties, the OGG file can be played and heard with no problem. 
But starting up the game gives no sound, even though volume in properties is set to 100.
I'm quite stumped.
Title: Re: No background music
Post by: Khris on Mon 12/11/2018 16:20:47
In other words, you have

function Room_AfterFadeIn ()
{
  aMusic1.Play(1);
  Display("Music should be playing now");
}


and the Display text shows up but no music?
Title: Re: No background music
Post by: Lewis on Tue 13/11/2018 08:20:12
Might seem like an obvious question but: is your other audio playing fine?

File size of the imported audio? I accidentally imported a massive uncompressed audio file into the game once and only realised 'cause there was like a 10 second pause before it started playing.
Title: Re: No background music
Post by: Mr Games on Tue 13/11/2018 11:04:55
Thank you for your responses. I have fixed the error by inserting the code via the Event section of properties.
Writing in the code directly didn't seem to work for some reason.
Title: Re: No background music
Post by: Slasher on Tue 13/11/2018 11:13:54
Quote from: Mr Games on Tue 13/11/2018 11:04:55
Thank you for your responses. I have fixed the error by inserting the code via the Event section of properties.
Writing in the code directly didn't seem to work for some reason.

you should only write code directly if there is no default properties event/function...
Title: Re: No background music
Post by: Khris on Tue 13/11/2018 13:33:41
Quote from: Mr Games on Tue 13/11/2018 11:04:55
Writing in the code directly didn't seem to work for some reason.
Yeah, with some exceptions like "on_mouse_click" in room scripts, all functions have to be linked to events or AGS won't ever call them.