Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Adding Sound, Need help

Author
Message
timer help
12
Years of Service
User Offline
Joined: 14th Jan 2014
Location:
Posted: 3rd Mar 2014 19:17
I need help with 2 things. I am making a quiz game and I want to make it so that if you get it right, it will make a "ding" sound. If you get it wrong, it will be "errr" I don't know where to get those sound files, and I don't know where to put the code. Here is my Quiz Game:

Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd Mar 2014 19:33
Remember that you're adding or subtracting from the game time depending on whether the user gets the answer correct or not. This is the same spot where you would want to play your sound.

You can find free sounds here: http://www.freesound.org/


Also, I don't remember if I pointed this out in your previous threads or not, but all those different test subroutines can be combined and cut down the amount of code by quite a lot.

ShellfishGames
13
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 3rd Mar 2014 22:32
load sound "<myfile>.wav", ID
play sound ID


Quote: "I don't know where to get those sound files"


here.

Quote: "I don't know where to put the code."


Exactly where you want the sound to be played. As Phaelax already pointed out - you want to play it when the user gives a right or wrong answer, so put the play sound just where this is evaluated. Load Sound obviously goes to the beginning of your program.

timer help
12
Years of Service
User Offline
Joined: 14th Jan 2014
Location:
Posted: 4th Mar 2014 19:29
I put this in:


then I added play sound here:


I tried doing it with and without my flash drive and it gives me the error: "Could not load sound at line 19" I spelled my file name correctly and I have no idea what is wrong with it.
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 5th Mar 2014 09:40
Can you upload the sound file? It's probably nothing, but the wav file could have some weird encoding or compression that DB doesn't like.

timer help
12
Years of Service
User Offline
Joined: 14th Jan 2014
Location:
Posted: 5th Mar 2014 18:54
Here is the sound we are trying to use
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 6th Mar 2014 04:02
It loads fine for me. But the file you uploaded is failbuz.wav.wav, but your code above says just failbuz.wav

timer help
12
Years of Service
User Offline
Joined: 14th Jan 2014
Location:
Posted: 6th Mar 2014 18:53
That was the problem, but now I have a new problem:
The Game works fine but I cannot hear the sound. For some reason it doesn't work:

tiffer
20
Years of Service
User Offline
Joined: 6th Apr 2006
Location: Scotland
Posted: 6th Mar 2014 19:02
can you upload the part of the program that plays the sound?

Cwatson
timer help
12
Years of Service
User Offline
Joined: 14th Jan 2014
Location:
Posted: 6th Mar 2014 19:06
Okay, here it is:


tiffer
20
Years of Service
User Offline
Joined: 6th Apr 2006
Location: Scotland
Posted: 6th Mar 2014 19:32 Edited at: 6th Mar 2014 19:34
If you pay attention to the logical structure here you will see that the reason you cant hear the sound is because it is constantly being restarted every loop.

The trouble wih the structure you've gone for is everything is being repeated.

simple fix


then when you exit the 'you_lost' screen you need to reset dontplaysound to 0

Cwatson
timer help
12
Years of Service
User Offline
Joined: 14th Jan 2014
Location:
Posted: 7th Mar 2014 19:05
I added the code to this and it worked, but it only works once. Whenever I restart the quiz the sound doesn't work anymore. I have to restart my game in order for the sound to work again.



I need it so that it can play the sound every time I restart the quiz.
ShellfishGames
13
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 7th Mar 2014 19:20
"then when you exit the 'you_lost' screen you need to reset dontplaysound to 0"

...I assume that should solve the problem.

timer help
12
Years of Service
User Offline
Joined: 14th Jan 2014
Location:
Posted: 7th Mar 2014 19:22
Doesn't that mean I need to restart my game? Sorry I am new to Dark Basic
ShellfishGames
13
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 7th Mar 2014 19:28
No, it means you replace this...

if inkey$() = "b" then gosub SubjectSelect
RETURN

by this...

if inkey$() = "b" then dontplaysound = 0 : gosub SubjectSelect
RETURN

I.e. then when you exit the 'YouLost' screen - which you do once gosub SubjectSelect is called because that stops your program form calling the YouLost subroutine - you need to reset dontplaysound to 0 - which basically means you set dontplaysound back to 0, which means you write dontplaysound = 0 into the code.

timer help
12
Years of Service
User Offline
Joined: 14th Jan 2014
Location:
Posted: 10th Mar 2014 18:04
New Question: I am trying to add sound for each answer I get right, and since I didn't fully make this game, I have no idea where to add it. Here is the place where I want to add it:


Please help!
ShellfishGames
13
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 10th Mar 2014 18:51
Well, comments are there for a reason - like these two:



I guess that sounds kind of promising.

timer help
12
Years of Service
User Offline
Joined: 14th Jan 2014
Location:
Posted: 11th Mar 2014 18:13
I entered one of the sounds for the correct answer, but the incorrect answer is giving me an error. This is what I tried to put:

It says I cannot load the sound.
ShellfishGames
13
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 11th Mar 2014 18:17
If it cannot load the sound, then the part where you call load sound is important, not the one where you play the sound.

Have you made sure you're using the correct file name? (Remember the failbuz.wav.wav problem from before) If so, are you using appropriate IDs (i.e. loading the sounds using different IDs, and using the correct ones when playing the sound)?

timer help
12
Years of Service
User Offline
Joined: 14th Jan 2014
Location:
Posted: 11th Mar 2014 18:31
Yes, I redownloaded the sound to make sure that the name wasn't the problem. I have no idea what is the problem
ShellfishGames
13
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 11th Mar 2014 18:55
Well, given the error message I assume that (1) you're either using a wrong file name or path, or (2) you're using a sound ID that is already in use. You can find out by replacing the line that causes the problem, which probably looks somewhat like this:



by this:



(replacing <filename> and <somevalue> with the exact values you've been using so far in the load sound line)

Then execute your code and see what it tells you. If it's still the same error message as before, that's kind of weird. But chances are it isn't.

Login to post a reply

Server time is: 2026-07-06 04:29:30
Your offset time is: 2026-07-06 04:29:30