Game Development Community

Play audio when press a key

by CIMO · in General Discussion · 06/16/2006 (10:35 am) · 16 replies

Hello i create this for play a audio file at my player when i press a key....
Step by step:

In "default.bind.cs" i put this
function doComandiVoce()
{
   commandToServer('ComandiVoceOrdine');
}
moveMap.bindCmd(keyboard, "p", "doComandiVoce(); ", "");

In "server\scripts\command.cs" i put this
function serverCmdComandiVoceOrdine(%val)
{
     exec("starter.fps/server/scripts/comandiVoce.cs");
}

I create a cs file with this name -> "comandiVoce.cs" an put in "server\scripts\"
(contained of "comandiVoce.cs")

datablock AudioProfile(ComandiVoceAudio)
{
   fileName = "~/data/sound/comandiVoce/stop.wav";
   description = AudioClose3d;
   preload = false;
};

function ComandiVoceOrdine( %this )
{
   %this.playAudio(0,ComandiVoceAudio);
   echo("ciao");
}

But not play the sound.....
In consolle...When i press the key...My script start...But the sound not play.....WHY?!?

#1
06/16/2006 (11:26 am)
Where to begin.

- It's bad practice to execute a script on the fly. Execute your comandiVoce.cs from game.cs with the rest of them.

- It's bad practice to issue commands to the server / client when it is completely unnecessary. It will clog up the network and result in poor performance.

- If your sound is a mono sound, use this
function ComandiVoceOrdine()
{
   ServerPlay3D(ComandiVoceAudio,0);
   echo("ciao");
}

- If your sound is a stereo sound, use this
function ComandiVoceOrdine()
{
   ServerPlay2D(ComandiVoceAudio,0);
   echo("ciao");
}

What you've written above is wrong on so many levels and I'm too tired to go through it right now.
#2
06/16/2006 (1:07 pm)
Never....
I test to change in this mode:
In "default.bind.cs" put this
function doComandoFerma(%val)
{
	if (%val)
		commandToServer('ComandoFerma');
}

moveMap.bind(keyboard, "ctrl 1", doComandoFerma);

In "server\scripts\player.cs" to and of file put this
datablock AudioProfile(ComandoFermaSound)
{
	fileName = "~/data/sound/comandiVoce/stop.wav";
	description = AudioClose3d;
	preload = true;
};

function serverCmdComandoFerma(%client)
{
	chatMessageTeam(%client, %team, "Ferma!");
	ServerPlay3D(ComandoFermaSound,0);
   echo("Ferma!");
}
but never....
The messagga in chat and in consolle all ok...But never sound!!! WHY?
#3
06/16/2006 (1:11 pm)
You're not giving it the right name for the audioProfile.
#4
06/16/2006 (1:17 pm)
Sorry i write this for error i correct my message...but the audio name is right....
and my sound don't play!!!
=(
#5
06/16/2006 (1:20 pm)
You're still not giving it the right name.

ServerPlay3D(ComandoFermaSound, 0);

Not sure if that's supposed to be quotes or not.

You also may want to check your paths and possible typos. You have the path as comandiVoce/stop.wav but I'm betting you meant comandoVoice/stop.wav.

Also check your sytem and speaker volume, Torque has a tendency to be on the quiet side.
#6
06/16/2006 (1:29 pm)
Never...
all ok...i see all...and the path all ok...
I up my speaker at 100% but never....
Any command in consolle for test play my audio file?
Never never never uff...But all exact...I see on "3d game programmer all in one"....uff
#7
06/16/2006 (1:36 pm)
Never...
all ok...i see all...and the path all ok...
I up my speaker at 100% but never....
Any command in consolle for test play my audio file?
Never never never uff...But all exact...I see on "3d game programmer all in one"....uff
#8
06/16/2006 (1:41 pm)
I test this....
ServerPlay2D(ComandoFermaSound); in consolle an all ok....
I restart....I press my "ctrl 1" key and ...... NOW LISTEN THE SOUND!!!!
WOW finally =) YES =) =)
But it's possible to play a
GlobalActionMap.bindCmd(keyboard, "ctrl g", "commandToServer('playCel',\"gogogo\");", "");
In my code when the start sound? =)
#9
06/16/2006 (1:45 pm)
I test this....
ServerPlay2D(ComandoFermaSound); in consolle an all ok....
I restart....I press my "ctrl 1" key and ...... NOW LISTEN THE SOUND!!!!
WOW finally =) YES =) =)
and i use this for "move" my player =D=D
NOW all ok
commandToServer('playCel', ferma);
WOW =)
#10
06/17/2006 (10:24 pm)
This is cool should be in torque forum not general. (So it can be searched on properly).
#11
06/19/2006 (4:45 am)
Question.....and problem =P
If a client press a key for talk.....The command work ONLY on server!!!!
Uff...
I woul:

- If in multyPlayerGame a client press a key ONLY client talk...

- If in multyPlayerGame a server press a key ONLY server talk...

The problem is on CommandToServer...Right?
For send ONLY command to client or ONLY to server?
#12
06/19/2006 (12:09 pm)
I use this in "default.bind.cs"... but never...
function ComandoRitirata(%val)
{
	datablock AudioProfile(ComandoRitirataSound)
	{
		fileName = "~/data/sound/comandiVoce/Ritirata.wav";
		description = AudioClose3d;
		preload = true;
	};
	if (%val)
		serverPlay2D(ComandoRitirataSound);
}

moveMap.bind(keyboard, "alt 8", ComandoRitirata);

The sound listen only server...

The problem is this?
serverPlay2D(ComandoRitirataSound);

how I must make?
#13
06/19/2006 (12:29 pm)
Never person help me?
#14
06/19/2006 (12:56 pm)
If you give people some time they will answer, we do have other things to do than writing your code. One thing I notice here is that you have a datablock declaration inside a function, I'm not sure that's legal, at least for me it's a new way of writing it.
#15
06/19/2006 (2:33 pm)
It goes well....Beautiful community indeed... the only community where One is answered in this way... has wants to in this way learn... Satisfied also and the draft....Ok you have lost a customer and also a customer!!
Thanks of all and excused for the time that I have made you to lose..Bye bye
#16
06/19/2006 (2:43 pm)
Cimo you should buy one of the many books written about torque. that way, you can learn at your own pace and have code and explanations to teach you.

whatever you do, please post in the correct forum. this goes in Torque Game Engine forum, not general discussion. not everyone here is using torque.