jbaudrand #1 Posted August 19, 2010 I'm trying to add sound in a little game, if joy0fire then missile0y=player0y-2:missile0x=player0x+4:AUDV0=8:AUDC0=4 p=p+1 if p=10 then AUDC0=0 :/ I though the counter will be in frame, but it's too long, it plays during 3-4 seconds, so I wonder what is my mistake. any idea? Quote Share this post Link to post Share on other sites
+RevEng #2 Posted August 19, 2010 (edited) Try adding a "=0" to the end of your if statement. Without it "p" will be some value from 0-255 when the fire button is pressed. Edited August 19, 2010 by RevEng Quote Share this post Link to post Share on other sites
jbaudrand #3 Posted August 20, 2010 Try adding a "=0" to the end of your if statement. Without it "p" will be some value from 0-255 when the fire button is pressed. Thanks, it's working better but I'm still trying to understand how it works: because when I set if p=2 then AUDC0=0, the sound stay as long as the missile is on screen, very strange test sound.bas Quote Share this post Link to post Share on other sites
+RevEng #4 Posted August 20, 2010 The problem in a nutshell, is that if missile0y<=240 then you're always skipping the bit of code that increments your sound timer and turns off the sound when it reaches 2. If you move that bit of code above your missile0y check, so it's executed each frame, then everything works out... *** EXISTING CODE if missile0y>240 then goto skip missile0y = missile0y-2:goto drawlooping skip if joy0fire then missile0y=player0y-2:missile0x=player0x+4:AUDV0=4:AUDC0=3:p=0 p=p+1 if p=2 then AUDC0=0 drawlooping *** NEW CODE p=p+1 if p=2 then AUDC0=0 if missile0y>240 then goto skip missile0y = missile0y-2:goto drawlooping skip if joy0fire then missile0y=player0y-2:missile0x=player0x+4:AUDV0=4:AUDC0=3:p=0 Quote Share this post Link to post Share on other sites
jbaudrand #5 Posted August 20, 2010 The problem in a nutshell, is that if missile0y<=240 then you're always skipping the bit of code that increments your sound timer and turns off the sound when it reaches 2. If you move that bit of code above your missile0y check, so it's executed each frame, then everything works out... *** EXISTING CODE if missile0y>240 then goto skip missile0y = missile0y-2:goto drawlooping skip if joy0fire then missile0y=player0y-2:missile0x=player0x+4:AUDV0=4:AUDC0=3:p=0 p=p+1 if p=2 then AUDC0=0 drawlooping *** NEW CODE p=p+1 if p=2 then AUDC0=0 if missile0y>240 then goto skip missile0y = missile0y-2:goto drawlooping skip if joy0fire then missile0y=player0y-2:missile0x=player0x+4:AUDV0=4:AUDC0=3:p=0 ooh thanks, the logic in programming is merciless.. Quote Share this post Link to post Share on other sites