Audio script problems

Non-platform specific questions.

Audio script problems

Postby draxido » Wed Jun 09, 2010 8:34 pm

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");
}
draxido
 
Posts: 18
Joined: Mon Feb 01, 2010 7:36 pm
Score: 0 Give a positive score

Re: Audio script problems

Postby jimmynewguy » Wed Jun 09, 2010 9:07 pm

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
Attachments
TEST.zip
(1.97 KiB) Downloaded 55 times
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Re: Audio script problems

Postby draxido » Wed Jun 09, 2010 9:50 pm

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.
draxido
 
Posts: 18
Joined: Mon Feb 01, 2010 7:36 pm
Score: 0 Give a positive score

Re: Audio script problems

Postby DST » Wed Jun 09, 2010 10:36 pm

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.
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest