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?
This code:
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:
function Room_AfterFadeIn()
{
aMusic1.Play();
}
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.
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!
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?
No music playing at all. But also no compile errors, kind of weird isn't it?
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.
Cassiebsg, if he did not have aMusic1 in his project tree, his script won't compile.
Ah, okay. Didn't knew that. :-[
Then maybe it's an event link missing?
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:
function Room_AfterFadeIn()
{
aMusic1.Play();
Display("Music should start playing now");
}
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?
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?
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.
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?
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.
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.
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...
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.