playSound not Functioning

Game Editor comments and discussion.

playSound not Functioning

Postby DrakeStoel » Wed Jun 01, 2016 2:02 am

So I've run into an interesting problem. I set up a simple playSound function. It works like this:

Collision --> On any side of: Player, Repeat while actor is colliding?: No --> playSound

This should work (unless I'm really REALLY missing something) but when I make my player walk into the collision object, nothing happens. What am I doing wrong? There are no other sounds or music playing at the time. Please help!
DrakeStoel
 
Posts: 43
Joined: Wed Oct 03, 2012 8:53 am
Score: 2 Give a positive score

Re: playSound not Functioning

Postby lcl » Thu Jun 02, 2016 10:16 am

Hi! I'll try to help you :)

There is many possible causes for the problem you are facing. If you could answer these few questions it'd be easier to try to find out what is causing the sound not to play.

What system are you on? Linux, Windows, Mac? There is differences between GE's audio support on these platforms.

What file type is the sound file you're trying to play? GE doesn't support sound files, for a list of supported files search the Game Editor wiki.

What version of Game Editor are you using? Also, have you tried using playSound2 instead?
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: playSound not Functioning

Postby DrakeStoel » Thu Jun 02, 2016 10:38 pm

Thanks!

I have Windows 7. The file is .wav, and I'm using gameEditor Beta v1.4.1.

I've tried using playSound2, as both the regular function, and by using a variable to give it it's own sound channel.

I've made a discovery though. When my all of the events of my player actor are disabled, the sound plays, so I've been trying to hunt down the culprit but haven't had any luck yet.
DrakeStoel
 
Posts: 43
Joined: Wed Oct 03, 2012 8:53 am
Score: 2 Give a positive score

Re: playSound not Functioning

Postby DrakeStoel » Thu Jun 02, 2016 11:15 pm

Ok! I found the problem, but I don't understand it.

So I have this fairly cluttered bit of code (I'm sure there's a more efficient way to do all this, but it works for now :P ) and the problem is under the "if(swamp == 0)" branch. It's the stopSound function (which I have nullified).

I don't understand why this one event would stop all other sounds not related to the player actor (I tried having other actors make sounds, but none worked before the tweak). I have been under the impression that giving a sound it's own integer, it shouldn't effect the other sounds currently playing.

Code: Select all
switch(attack)
{
// Not Attacking
case 0:
// Key Test
attack = (key[KEY_x]==1);
nkeys = key[KEY_LEFT]+key[KEY_RIGHT]+key[KEY_UP]+key[KEY_DOWN];
// Set Direction & Speed

if (swamp == 0)
{
dir = (1*key[KEY_UP]+2*key[KEY_LEFT]+3*key[KEY_DOWN]+4*key[KEY_RIGHT])*(nkeys<2);
player_collide.angle = dir*90;
player_collide.directional_velocity = 3*(dir>0);
    //stopSound(SFXSwampWalk);
    DestroyTimer("SwampWalk");
}
else if (swamp == 2)
{
   dir = (1*key[KEY_UP]+2*key[KEY_LEFT]+3*key[KEY_DOWN]+4*key[KEY_RIGHT])*(nkeys<2);
   player_collide.angle = dir*90;
   player_collide.directional_velocity = 2*(dir>0);
}
else if (swamp == 1)
{
dir = (1*key[KEY_UP]+2*key[KEY_LEFT]+3*key[KEY_DOWN]+4*key[KEY_RIGHT])*(nkeys<2);
player_collide.angle = dir*90;
player_collide.directional_velocity = 1.5*(dir>0);
if (player_collide.directional_velocity == 0)
{
    stopSound(SFXSwampWalk);
    DestroyTimer("SwampWalk");
}
}



It's funny because the idea behind this code still works as intended, so it's even more strange to me...
DrakeStoel
 
Posts: 43
Joined: Wed Oct 03, 2012 8:53 am
Score: 2 Give a positive score

Re: playSound not Functioning

Postby lcl » Fri Jun 03, 2016 1:02 pm

What value does the variable SFXSwampWalk have? If it's 0 that will make it stop all sounds. Have you tried if the same problem occurs with Game Editor 1.4.0?
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: playSound not Functioning

Postby DrakeStoel » Fri Jun 03, 2016 9:35 pm

Oooooooohhhhhhhh... I'm now thinking I don't actually understand how sounds as variables work :oops:

So this is how I thought it worked:
Setting up the variable:
Global Code -> Vars
Code: Select all
int SFXSwampWalk


and the activation event
Collision->Any Side of (player)->Script Editor:
Code: Select all
SFXSwampWalk = playSound2 (blah blah blah);


But from your question, I feel like that is very wrong because I don't have it set as a number, rather a different function.

Also, I have tried it in older versions, but none of them seem to be backwards compatable and I keep getting the message: This needs the latest version of gameEditor to open (or something similar)
DrakeStoel
 
Posts: 43
Joined: Wed Oct 03, 2012 8:53 am
Score: 2 Give a positive score

Re: playSound not Functioning

Postby lcl » Fri Jun 03, 2016 10:31 pm

No, you haven't understood anything wrong, that is how you're supposed to catch the sound channel used by the sound.
Code: Select all
SFXSwampWalk = PlaySound2(...);

This code is correct, it plays the sound and stores what PlaySound2 returns into the SFXSwampWalk variable. And PlaySound2 returns the number of the channel used, so that's right. You're not setting SFXSwampWalk to the function, don't worry. I'm sorry I made you confused with my question. :oops:

What I meant to do was to ask what value the variable gets - e.g. to ask you to check that by using a text actor to show the value of SFXSwampWalk. If PlaySound2 fails it will return 0 instead of the channel number. And that could then result in stopSound being called with the value 0, thus causing it to stop all sounds in the game.

I could also take a look at the .ged if you'd like.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: playSound not Functioning

Postby DrakeStoel » Fri Jun 03, 2016 11:14 pm

Oh, ok. Sorry, I think it's me to blame! I didn't quite understand the question. I read through it pretty quickly :(

Anyways, I set up the text actor, and interestingly enough, it was switching between 2 and 3. My theory is that it is because I have it set to loop on a timer because I couldn't figure out a better way without it interrupting... Something... I can't remember what though :lol: And it's just switching quickly between the two channels to compensate?

I checked the other sounds (ie opening doors, getting keys, etc.) and they were also returning two. And these numbers were all the same, both with the original code, and the edited one.

It really isn't a problem now, it all works fine. It's just oddly frustrating not knowing why it doesn' work :lol:
DrakeStoel
 
Posts: 43
Joined: Wed Oct 03, 2012 8:53 am
Score: 2 Give a positive score

Re: playSound not Functioning

Postby lcl » Fri Jun 24, 2016 12:21 pm

DrakeStoel wrote:It really isn't a problem now, it all works fine. It's just oddly frustrating not knowing why it doesn' work :lol:

Okay. :D But yeah, I'd also like to know why it won't work.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest