PlaySound not working?

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

EggXzaB

BinaryZero Error maker .. o_O
Jul 15, 2003
69
0
0
I got an exec :
Code:
#EXEC AUDIO IMPORT FILE="Sounds/gaan.wav" NAME="go"

And a code to play the sound..
Code:
Function BuyTime(bool s)
{
   Local Pawn p;

   foreach AllActors(class'Pawn', p)
   {
      if(!s)
      {
         p.GroundSpeed = 300;
         PlaySound(Sound'go');
      }
      else if(s)
      {
         p.GroundSpeed = 1;

      }
   }
}

But it doesnt play my sound .. whats wrong ?
I got this from a 3dbuzz.com VTM, and it works there ..

:(
 

Wormbo

Administrator
Staff member
Jun 4, 2001
5,913
36
48
Germany
www.koehler-homepage.de
What class is this in? Your PlaySound function is executed for this actor's code, not for the pawns, so the sound is played at the actor's location. Usually this results in the sound not being heard by any player.

[rant]
That code is from 3dbuzz.com? Pardon me, but it sucks. ;)
You should iterate through the Controllers using the linked list in Level.ControllerList and playing that sound for the controllers' pawns if the Controller is a PlayerController. This is much more efficient than using AllActors.
Even DynamicActors would have been more efficient than AllActors. :con:
[/rant]
 

EggXzaB

BinaryZero Error maker .. o_O
Jul 15, 2003
69
0
0
Wormbo said:
You should iterate through the Controllers using the linked list in Level.ControllerList and playing that sound for the controllers' pawns if the Controller is a PlayerController.

Explain?
icon5.gif
 

[SAS]Solid Snake

New Member
Jun 7, 2002
2,633
0
0
40
New Zealand
www.digitalconfectioners.com
foreach AllActors(class'Pawn', p)

This iterator is very time/CPU consuming, hence it is very slow. There is already a list that tells us the PlayerControllers in the level (This is the list of players). Thus we should just go through the list that is already there than using this wasteful code.

PlaySound(Sound'go');
The PlaySound may also not work depending where you have put it as well. It 'may' play but the object you have asked to play the sound is abstract or doesn't exist. You may want to put this into a PlayerController and tell the PlayerController to make the sound via ClientPlaySound I think ...
 

Wormbo

Administrator
Staff member
Jun 4, 2001
5,913
36
48
Germany
www.koehler-homepage.de
EggXzaB said:
Epic knows how slow their ForEach iterators can be, so they provided us with some efficient linked lists to speed things up. One of these lists is the ControllerList which contains all controllers (not only PlayerControllers) in a level.
To iterate through the controller list you use a for loop like this:
Code:
local Controller thisController;

for (thisController = Level.ControllerList;
     thisController != None;
     thisController = thisController.nextcontroller) {
  //put your code here
}
This is not yet what you want because it iterates through all controllers, this includes those that don't have a pawn or aren't even players at all. I guess you want to modify all pawns, so let's add in your code:
Code:
local Controller thisController;

for (thisController = Level.ControllerList;
     thisController != None;
     thisController = thisController.nextcontroller) {
  if (thisController.Pawn != None) {
    if (!s) {
      thisController.Pawn.GroundSpeed = 300;
      if (thisController.IsA('PlayerController'))
        thisController.Pawn.PlaySound(Sound'go');
    }
    else if (s) {
      thisController.Pawn.GroundSpeed = 1;
    }
  }
}
I silently inserted some more code than you used: thisController.Pawn.PlaySound()
This makes sure the pawn plays the sound, not the class (GameInfo?) this code is in. Also note how PlaySound only gets called if the Pawn is controlled by a PlayerController. Bots wouldn't hear it anyway, so why wasting resources with playing the Go sound for them? :)
 

EggXzaB

BinaryZero Error maker .. o_O
Jul 15, 2003
69
0
0
Right, thx for teh info guys, I used Wormbo's code for my function :
Code:
Function BuyTijd(bool s)
{

local Controller thisController;

for (thisController = Level.ControllerList;
     thisController != None;
     thisController = thisController.nextcontroller) 
{
  if (thisController.Pawn != None) 
  {
    if (!s) 
    {
      thisController.Pawn.GroundSpeed = 300;
      if (thisController.IsA('PlayerController'))
      thisController.Pawn.PlaySound(Sound'go');
      BroadcastLocalizedMessage(class'bz_loc_msgs', 0);
      thisController.Pawn.bNoWeaponFiring = false;
    }
    else if (s)
    {
      thisController.Pawn.GroundSpeed = 1;
      thisController.Pawn.bNoWeaponFiring = true;
    }
  }
}
}
But still, the sound is not played ...
I'll try the ClientPlaySound mentioned by Snake :)
 

EggXzaB

BinaryZero Error maker .. o_O
Jul 15, 2003
69
0
0
Yeah, but its just dutch for me to understand it better :)
And most of the time I convert them to english later on ..
 

EggXzaB

BinaryZero Error maker .. o_O
Jul 15, 2003
69
0
0
Hmm, I dont get it, PlayerController is a subclass of Controller,
and the ClientPlaySound function is defined in the playercontroller, but if I do
Code:
thisController.ClientPlaySound(Sound'go',true,0.7);

It tells me that 'ClientPlaySound' is unrecognized in class 'Controller'
Maybe it should be PlayerController.ClientPlaySound but I guess this has to work also right?
Eyecrazy.gif


[EDIT]
Offcourse not, the ClientPlaySound function is set in PlayerController and not in Controller itself, dumbass :p
[/EDIT]

Even this
Code:
if (thisController.IsA('PlayerController'))      {
         foreach AllActors(class'PlayerController', P)
         P.ClientPlaySound(Sound'go');
      }
Doesnt work :(

But it gives me no compile errors, just dont hear the sound ..
 
Last edited:

EggXzaB

BinaryZero Error maker .. o_O
Jul 15, 2003
69
0
0
Omg !
Seemed that i saved the file with wrong khz and so ..
Now it works .. thx for the help though all, I feel so stupid :( ..