Page 1 of 1

Audio script problems

PostPosted: Wed Jun 09, 2010 8:34 pm
by draxido
Hello again everyone.

I have a line of code that doesnt seem to want to work. as far as i know, the code determines if the event actor (in this case a bullet) is less than 350 pixels away from the player, it will play the sound. If its greater, then it gets destroyed. But. it seems to still trigger the sound, despite being well over the 350 pixel marker.

Any ideas how i can fix it up?
heres the code

Code: Select all
if(distance(x, y,player.x, y) < 350)
{
PlaySound2("data/bullet hit tank.wav", 1.000000, 1, 0.000000);
}
else if(distance(x, y, player.x, y) > 350)
{
DestroyActor("Event Actor");
}

Re: Audio script problems

PostPosted: Wed Jun 09, 2010 9:07 pm
by jimmynewguy
i tested this code and it seems to work from me. i copied and pasted it and changed the sound is all. not sure what to tell you but to have a look at this

Re: Audio script problems

PostPosted: Wed Jun 09, 2010 9:50 pm
by draxido
sorry, i didnt explain properly what was wrong.
I meant that the sound still plays, even though the player is over 350 pixles away.
I cant seem to figure out whats wrong.

Re: Audio script problems

PostPosted: Wed Jun 09, 2010 10:36 pm
by DST
I'm not sure if you meant to use a 1-vertice distance check, but you have
distance(x, y, player.x, y); So only the x axis is being checked.
If that is the case, then simply use subtraction instead of distance();

Code: Select all
int xs=abs(x-player.x);  //abs removes +- from the final answer
if(xs<=350){   //remember to tell it what to do on =
playsound etc;
}
else{
DestroyActor("Event Actor");
}



Otherwise, use distance(x, y, player.x, player.y);

It's always a good idea to use a variable to hold the value, instead of performing the check inside the if statement.
You have 2 distance checks, where you only need one.