Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Dreemurrrr on Mon 14/03/2022 03:40:37

Title: Need help with aMusic1.Play()
Post by: Dreemurrrr on Mon 14/03/2022 03:40:37
im trying to set up a simple test run of my game that has some basic things in it like talking and stuff but i cant get the bg music to play. I have read through literealy everything i could find to try to fix this but nothing is working.

I want the song to play when the game fades in but when i run the game there is no sound.
right now my code says:
Code (ags) Select
function room_AfterFadeIn() {
    AudioChannel* chan = aMusic1.Play();
    chan.Volume = 50;
}


ive tried alot of other codes but none of them work either. i have done amusic1.play on its own and with other things its just so confusing for me and i cant figure out what im doing wrong :( :(

(please be patient with me i struggle to understand things)
Title: Re: Need help with aMusic1.Play()
Post by: Khris on Mon 14/03/2022 06:48:54
My guess is the function doesn't actually run because you typed it yourself, i.e. it's not linked to the room event.
Open the room events list and check whether it says room_AfterFadeIn in the field next to the event.

Just typing out the function into a room script only works for a bunch of special functions like on_mouse_click, all event functions should be created via the [...] button in the events pane.
Title: Re: Need help with aMusic1.Play()
Post by: Dreemurrrr on Mon 14/03/2022 10:58:33
i just tried that but the music still isnt playing.  :(
Title: Re: Need help with aMusic1.Play()
Post by: eri0o on Mon 14/03/2022 11:18:00
If you place a Display ("after fade in"); command in this function, does it writes anything on the screen?
Title: Re: Need help with aMusic1.Play()
Post by: heltenjon on Mon 14/03/2022 11:54:07
Have you added aMusic1 in the Music folder under Audio while in the editor?
Title: Re: Need help with aMusic1.Play()
Post by: Pogwizd on Mon 14/03/2022 12:23:03
Sorry, I didn't quite get if playing the audio clip on its own works for you?
If not, could you check how long is the clip? Is it shorter than one second by any chance?
Title: Re: Need help with aMusic1.Play()
Post by: Dreemurrrr on Mon 14/03/2022 19:57:40
Quote from: eri0o on Mon 14/03/2022 11:18:00
If you place a Display ("after fade in"); command in this function, does it writes anything on the screen?

I tried that and this happened

(https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/6118e0c5-8321-43f3-918c-6b72fc2bb069/df1pqsj-222d4f9f-1bec-4aa5-9cc6-d08bf97520b1.png/v1/fill/w_1192,h_670,q_70,strp/fd_by_dreemurrrr_df1pqsj-pre.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7ImhlaWdodCI6Ijw9NzIwIiwicGF0aCI6IlwvZlwvNjExOGUwYzUtODMyMS00M2YzLTkxOGMtNmI3MmZjMmJiMDY5XC9kZjFwcXNqLTIyMmQ0ZjlmLTFiZWMtNGFhNS05Y2M2LWQwOGJmOTc1MjBiMS5wbmciLCJ3aWR0aCI6Ijw9MTI4MCJ9XV0sImF1ZCI6WyJ1cm46c2VydmljZTppbWFnZS5vcGVyYXRpb25zIl19.Exn7CbQv4tW6FlX7-zsf95OZyT3z_xnpJv7FOqfjhGk)
Title: Re: Need help with aMusic1.Play()
Post by: eri0o on Mon 14/03/2022 20:15:06
I don't know yet what it's happening yet, did you create the after fade in function through the event (âš¡) tab and then do something like this in the script Editor:

Code (ags) Select
function room_AfterFadeIn() {
    AudioChannel* chan = aMusic1.Play();
    chan.Volume = 50;
    Display ("Test After Fade In!!!!");
}


In the meantime can you take a look here on how interactions, the property grid and events work: https://adventuregamestudio.github.io/ags-manual/acintro3.html
Title: Re: Need help with aMusic1.Play()
Post by: Cassiebsg on Mon 14/03/2022 20:55:39
About that error, seems like you have created an event for room_load (before fade-in) but deleted it from the script?


Either way, you can't have a linked function pointing to a non-existing function in script.
Solution: Delete the name of the function in the event panel, or recreate the function in the script (even if you leave it empty of any command lines).
Title: Re: Need help with aMusic1.Play()
Post by: Khris on Tue 15/03/2022 00:21:57
Here's some clarification:

(https://i.imgur.com/P4WewGZ.png)

The event (1) is triggered by the user or the engine.
If a function name is entered in the 2nd column (2), AGS will look for the function in the respective script and call it.
If the function (3) exists, it runs.

Problems:
If the function (3) exists but isn't entered at (2), nothing happens when the event (1) is triggered.
If a function name is entered at (2) but no function of that name exists in the script, the error you got is the result (no such function in script).
Title: Re: Need help with aMusic1.Play()
Post by: Dreemurrrr on Tue 15/03/2022 02:15:13
Quote from: eri0o on Mon 14/03/2022 20:15:06
I don't know yet what it's happening yet, did you create the after fade in function through the event (âš¡) tab and then do something like this in the script Editor:

Code (ags) Select
function room_AfterFadeIn() {
    AudioChannel* chan = aMusic1.Play();
    chan.Volume = 50;
    Display ("Test After Fade In!!!!");
}


In the meantime can you take a look here on how interactions, the property grid and events work: https://adventuregamestudio.github.io/ags-manual/acintro3.html

ok now im getting this instead :(
(https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/6118e0c5-8321-43f3-918c-6b72fc2bb069/df1qemy-5fc67fdc-170a-4341-8a35-01fe6dbf9450.png?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7InBhdGgiOiJcL2ZcLzYxMThlMGM1LTgzMjEtNDNmMy05MThjLTZiNzJmYzJiYjA2OVwvZGYxcWVteS01ZmM2N2ZkYy0xNzBhLTQzNDEtOGEzNS0wMWZlNmRiZjk0NTAucG5nIn1dXSwiYXVkIjpbInVybjpzZXJ2aWNlOmZpbGUuZG93bmxvYWQiXX0.o9waftU2_J4zp4ON-ZY7DKQ1xxO0x6nggfQUIi76YiA)
Title: Re: Need help with aMusic1.Play()
Post by: Snarky on Tue 15/03/2022 07:35:07
That means that aMusic1 has failed to play.
Title: Re: Need help with aMusic1.Play()
Post by: Khris on Tue 15/03/2022 07:40:06
What exactly is aMusic1? What type of file? Where did you import it? Can you play it in the editor?
Title: Re: Need help with aMusic1.Play()
Post by: Dreemurrrr on Tue 15/03/2022 10:27:24
its a mp3 file. It lets me play it in the editor. its in the music folder
Title: Re: Need help with aMusic1.Play()
Post by: eri0o on Tue 15/03/2022 11:09:31
Can you use an ogg file instead? Maybe for some reason this mp3 file is not compatible.

Other thing is if the computer has no device to play the audio (e.g. desktop computer on Windows without speakers and without headphones), I think that channel will return a nullpointer too.
Title: Re: Need help with aMusic1.Play()
Post by: Dreemurrrr on Tue 15/03/2022 11:25:00
Do you know a good site to convert it to ogg? I'm new to this kinda thing I'm sorry.
Title: Re: Need help with aMusic1.Play()
Post by: eri0o on Tue 15/03/2022 11:33:35
I usually rely on Audacity for my audio needs: https://www.audacityteam.org/

I don't know any online website. :/
Title: Re: Need help with aMusic1.Play()
Post by: Khris on Tue 15/03/2022 11:44:17
Here's one: https://audio.online-convert.com/convert-to-ogg

Still, mp3 should work fine. Can you upload the file so we can test this? Also check that you didn't accidentally disable sound in your winsetup.
Title: Re: Need help with aMusic1.Play()
Post by: Dreemurrrr on Tue 15/03/2022 15:11:17
Quote from: eri0o on Tue 15/03/2022 11:09:31
Can you use an ogg file instead? Maybe for some reason this mp3 file is not compatible.

Other thing is if the computer has no device to play the audio (e.g. desktop computer on Windows without speakers and without headphones), I think that channel will return a nullpointer too.

ok i changed it to ogg and ims till getting the same error. when i removed the volume thing it still didnt play. and i have audio devices so i rlly dont understand :(
Title: Re: Need help with aMusic1.Play()
Post by: Dreemurrrr on Tue 15/03/2022 15:15:17
Quote from: Khris on Tue 15/03/2022 11:44:17
Here's one: https://audio.online-convert.com/convert-to-ogg

Still, mp3 should work fine. Can you upload the file so we can test this? Also check that you didn't accidentally disable sound in your winsetup.

https://drive.google.com/drive/folders/1viX_4-XIxO4dbK9ec9RRgDxdHFPV-WzG?usp=sharing

here is the file as an ogg now
Title: Re: Need help with aMusic1.Play()
Post by: eri0o on Tue 15/03/2022 15:19:38
On Winsetup, click advanced. At the right, there's a mention about Sound Digi device, is the sound enabled there?
Title: Re: Need help with aMusic1.Play()
Post by: Khris on Tue 15/03/2022 17:42:29
I can easily reproduce the error by turning the sound off in winsetup. That has to be it.

That also means there's what I would consider a bug in AGS; turning off the sound should absolutely not make the game crash like that.
I get what's happening but the setting shouldn't mean I have to wrap every Volume command in a null pointer check, especially since somebody might try to run the game on a system without any audio hardware.