Author Topic: Sound system (i ned halp)  (Read 6666 times)

So for the past 3 days ive been trying to get his sound system to work
Code: [Select]
function ARX160Image::onFire(%this, %obj, %slot)
{
if(dist < 50)
ServerPlay3D(ARX160Fire,%obj.getTransform());
     else if(dist < 100)
ServerPlay3D(ARX160Med,%obj.getTransform());
     else
ServerPlay3D(ARX160Long,%obj.getTransform());

And the whole time it refuses to work. Can you guys tell me what  I AM doing wrong so i can fix this.

http://www.mediafire.com/download/7wd4761v8nvabn4/Weapon_ARX160.zip
Heres the gun that i was working on. Hope you guys can fix it.
« Last Edit: October 11, 2014, 03:48:07 PM by Ctrooper »

Where is %dist defined?

You also have a missing end bracket for the close of the function.

Quote
Where is %dist defined?
Your right, shet
Quote
You also have a missing end bracket for the close of the function.
There are other operations in this OnFire function, this one is the first operation. Or does it need to be a separate function?

Or does it need to be a separate function?
It doesn't, also be sure to remember to define dist as an actual variable instead of a word as you have there.

It doesn't, also be sure to remember to define dist as an actual variable instead of a word as you have there.
so i should end up with the function looking like this:
Code: [Select]
function ARX160Image::onFire(%this, %dist %obj, %slot)
{
if(%dist < 50)
ServerPlay3D(ARX160Fire,%obj.getTransform());
     else if(%dist < 100)
ServerPlay3D(ARX160Med,%obj.getTransform());
     else
ServerPlay3D(ARX160Long,%obj.getTransform());

::onFire() has no distance argument. Instead you are populating %dist with the object, %object with the slot, and %slot gets no value.

::onFire() has no distance argument. Instead you are populating %dist with the object, %object with the slot, and %slot gets no value.
so i do not need to put %dist in the OnFire()?

so i do not need to put %dist in the OnFire()?

It's not one of the arguments of the function. Instead, you need to define it within the function.

It's not one of the arguments of the function. Instead, you need to define it within the function.
In other words, you can't just put the variable there and have it automatically filled for you. You have to actually calculate the distance yourself, and from what I can tell you're approaching this whole problem from the wrong direction anyways.

In other words, you can't just put the variable there and have it automatically filled for you. You have to actually calculate the distance yourself, and from what I can tell you're approaching this whole problem from the wrong direction anyways.
but ithought i already calculated the distance with
Code: [Select]
if(%dist < 50)Also im not sure what you mean by
Quote
from what I can tell you're approaching this whole problem from the wrong direction anyways.
Slap me in the right direction please

%dist < 50 does not assign a value to %dist. It checks if the value of %dist is less than 50. Since %dist has no value at all, it will always be less than fifty.

You have to make %dist have a value. Simply listing it in the arguments of the function will not make Torque magically know you want the distance to go there. Actually, listing it there doesn't even help me understand what you want to go in that variable, and I am most decidedly more intelligent than Torque. Clearly dist is short for distance, but distance between what? I'm guessing you want the distance between you and the object you're shooting, but at the time of onFire nobody knows what that distance is. You can do a raycast and see how far ahead the object you're pointed at is, but if someone flies in front of the bullet the bullet won't travel that distance so it'll play the wrong sound. You can wait until the bullet hits something and then play the sound, but then the fire sound won't play until the bullet collides. Realistically there's no way to detect how far the bullet will travel until it actually hits something.
« Last Edit: October 08, 2014, 09:16:28 PM by $trinick »

%dist < 50 does not assign a value to %dist. It checks if the value of %dist is less than 50. Since %dist has no value at all, it will always be less than fifty.

You have to make %dist have a value. Simply listing it in the arguments of the function will not make Torque magically know you want the distance to go there. Actually, listing it there doesn't even help me understand what you want to go in that variable, and I am most decidedly more intelligent than Torque. Clearly dist is short for distance, but distance between what? I'm guessing you want the distance between you and the object you're shooting, but at the time of onFire nobody knows what that distance is. You can do a raycast and see how far ahead the object you're pointed at is, but if someone flies in front of the bullet the bullet won't travel that distance so it'll play the wrong sound. You can wait until the bullet hits something and then play the sound, but then the fire sound won't play until the bullet collides. Realistically there's no way to detect how far the bullet will travel until it actually hits something.
okay sweet, but thats not what im using this sound system for, im using it for a sort of "Weapon sound layer" kind of thing, so the farther away you are, the quieter the gun shot sounds. With that being said, how would i define the distance?

okay sweet, but thats not what im using this sound system for, im using it for a sort of "Weapon sound layer" kind of thing, so the farther away you are, the quieter the gun shot sounds. With that being said, how would i define the distance?
My entire point was that you never told us what you wanted, so we had no idea how to tell you how to fix your code.

You're gonna need to use a spherical ray search to find nearby players then play a sound to each of them individually. I already explained that one to you here, and the code that I posted later in that topic can easily be adapted to work in this function.

Once you've found a player, to calculate the distance between it and %obj use %dist = vectorDist(%shooter.getTransform(), %hearPlayer.getTransform());

Then you have to play the sound in 3d to the player. Once you found the player, use %foundPlayer.client.play3D( sound profile, %obj.getTransform()) to play a sound on it.

Then you have to play the sound in 3d to the player. Once you found the player, use %foundPlayer.client.play3D( sound profile, %obj.getTransform()) to play a sound on it.
I was under the impression that only 2D sound can be played directly to a client.

I was under the impression that only 2D sound can be played directly to a client.

I thought that too for some reason, but I searched on the forums and found multiple people using the function so I went with it. I just checked in BL too and the method does exist. Whether it works or not is a mystery, but I don't see why it wouldn't.