Need help with aMusic1.Play()

Started by Dreemurrrr, Mon 14/03/2022 03:40:37

Previous topic - Next topic

Dreemurrrr

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
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)

Khris

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.

Dreemurrrr

i just tried that but the music still isnt playing.  :(

eri0o

If you place a Display ("after fade in"); command in this function, does it writes anything on the screen?

heltenjon

Have you added aMusic1 in the Music folder under Audio while in the editor?

Pogwizd

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?

Dreemurrrr

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


eri0o

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
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

Cassiebsg

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).
There are those who believe that life here began out there...

Khris

Here's some clarification:



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).

Dreemurrrr

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
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 :(

Snarky

That means that aMusic1 has failed to play.

Khris

What exactly is aMusic1? What type of file? Where did you import it? Can you play it in the editor?

Dreemurrrr

its a mp3 file. It lets me play it in the editor. its in the music folder

eri0o

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.

Dreemurrrr

Do you know a good site to convert it to ogg? I'm new to this kinda thing I'm sorry.

eri0o

I usually rely on Audacity for my audio needs: https://www.audacityteam.org/

I don't know any online website. :/

Khris

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.

Dreemurrrr

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 :(

Dreemurrrr

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

SMF spam blocked by CleanTalk