Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (TedMar, AndrewAMD, alibaba, 7th_zorro, 1 invisible), 1,049 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Play sound only one time on key press. #373544
06/10/11 22:04
06/10/11 22:04
Joined: Jul 2001
Posts: 4,801
netherlands
Realspawn Offline OP

Expert
Realspawn  Offline OP

Expert

Joined: Jul 2001
Posts: 4,801
netherlands
I use this simple piece of code

Code:
SOUND* hits_snd = "mix1.wav";
{
if (key_u ==1 )
snd_play(hits_snd,100,0);				
}



The problem is that when i press the U key the sound plays but gets repeated when the key is still pressed. One key release it stops. So instead of playing the sound once it gives now a lot of noice echoes and not the sound that should be heared.

Any one ? laugh


Find all my tutorials & Workshops at : www.rp-interactive.nl

Creativity starts in the brain
Re: Play sound only one time on key press. [Re: Realspawn] #373549
06/10/11 22:13
06/10/11 22:13
Joined: Aug 2009
Posts: 1,438
Spain
painkiller Offline
Serious User
painkiller  Offline
Serious User

Joined: Aug 2009
Posts: 1,438
Spain
Code:
while(1)
{
   if (key_u)
   {
      snd_play(hits_snd,100,0);
      while(key_u) wait(1);				
   }
wait(1);
}




3D Gamestudio A8 Pro
AMD FX 8350 4.00 Ghz
16GB RAM
Gigabyte GeForce GTX 960 4GB
Re: Play sound only one time on key press. [Re: Realspawn] #373550
06/10/11 22:14
06/10/11 22:14
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
Use on_u instead of key_u...

Or if you really want key_u:
Code:
var soundhandle = 0;

SOUND* hits_snd = "mix1.wav";
{
   if (key_u ==1 && !soundhandle)
   soundhandle = snd_play(hits_snd,100,0);				
}



Last edited by Widi; 06/10/11 22:15.
Re: Play sound only one time on key press. [Re: Widi] #373561
06/10/11 23:48
06/10/11 23:48
Joined: Jul 2001
Posts: 4,801
netherlands
Realspawn Offline OP

Expert
Realspawn  Offline OP

Expert

Joined: Jul 2001
Posts: 4,801
netherlands


mmm i must getting tired laugh Bassicly i want to play a sound every time
my player does an attack move. If i add the snd_play i get the
annoying echo or the player gets stuck in the animation.


Here's my player movement for tonight i give up i really need some sleepzzzzz
Although i am happy that i accomplished the movement today laugh learned something at least laugh


Code:
action player_code() // attach this action to your player
{
	var movement_speed = 10; // movement speed
	var anim_percentage;
	VECTOR temp;
	player = my; // I'm the player
	while (1)
	{
		
		vec_set (temp.x, my.x); // trace 10,000 quants below the player
		temp.z -= 3000;
		temp.z = -c_trace (my.x, temp.x, IGNORE_ME | IGNORE_PASSABLE | USE_BOX) + 4; // play with 20
		temp.x = movement_speed * (key_w - key_s) * time_step;
		temp.y = 0;
		c_move (my, temp.x, nullvector, IGNORE_PASSABLE | GLIDE);
		if (!key_w && !key_s) // the player isn't moving?
		{
			ent_animate(my, "idle", anim_percentage, ANM_CYCLE); // play the "stand" animation
			anim_percentage += 2 * time_step; // 5 = animation speed
		}
		else // the player is moving?
		{
			
			ent_animate(my, "walkr", anim_percentage, ANM_CYCLE); // play the "walk" animation 
			anim_percentage += 4 * time_step * (key_w - key_s);			
		}
		{
			if (key_c ==1 )			
			{
				ent_animate(my, "attack", anim_percentage, ANM_CYCLE); // play the "walk" animation
				anim_percentage += 3 * time_step; // 8 = animation speed	
											
			}
			if (key_v ==1 )
			{
				ent_animate(my, "attackk", anim_percentage, ANM_CYCLE); // play the "walk" animation
				anim_percentage += 3 * time_step; // 8 = animation speed		
			}
			if (key_b ==1 )
			{
				ent_animate(my, "atackkk", anim_percentage, ANM_CYCLE); // play the "walk" animation
				anim_percentage += 3 * time_step; // 8 = animation speed				
			}
			if (key_f ==1 )
			{
				ent_animate(my, "attackkkk", anim_percentage, ANM_CYCLE); // play the "walk" animation
				anim_percentage += 3 * time_step; // 8 = animation speed					
			}
			if (key_g ==1 )
			{
				ent_animate(my, "attackkkkk", anim_percentage, ANM_CYCLE); // play the "walk" animation
				anim_percentage += 1 * time_step; // 8 = animation speed					
			}
			if (key_g ==1 )
			{
				ent_animate(my, "attackkkkkk", anim_percentage, ANM_CYCLE); // play the "walk" animation
				anim_percentage += 1 * time_step; // 8 = animation speed						
			}
		
			if (key_u ==1) 
   		{
				ent_animate(my, "jump", anim_percentage, ANM_CYCLE); // play the "walk" animation
				anim_percentage += 1 * time_step; // 8 = animation speed		

				
			
		
         
          }
          wait(1);
          }
         
        }
        }



Last edited by Realspawn; 06/10/11 23:51.

Find all my tutorials & Workshops at : www.rp-interactive.nl

Creativity starts in the brain
Re: Play sound only one time on key press. [Re: Realspawn] #373584
06/11/11 10:38
06/11/11 10:38
Joined: Sep 2009
Posts: 84
Theil Offline
Junior Member
Theil  Offline
Junior Member

Joined: Sep 2009
Posts: 84
SOUND* hits_snd = "mix1.wav";

function playSound()
{
snd_play(hits_snd,100,0);
}

action player_code()
{

on_u = playSound;

while(1)
{

if (key_u ==1)
{
ent_animate(my, "jump", anim_percentage, ANM_CYCLE); // play the "walk" animation
anim_percentage += 1 * time_step; // 8 = animation speed
}
wait(1);
}

}

Re: Play sound only one time on key press. [Re: Theil] #373586
06/11/11 10:47
06/11/11 10:47
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Just make simple logical "if" comparison in a while loop, like this:
Code:
if(run_once == 0)
{
     snd_play(attack_wav,80,0);
     run_once = 1;
}

You should remember that in while loop everything works each frame again and again.
So with this comparison sound will play only once. To play it again, you'll need to set "run_once" back to zero.
Set it back to zero when animation fully played, check that by animation percentage.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Play sound only one time on key press. [Re: 3run] #373603
06/11/11 12:30
06/11/11 12:30
Joined: Jul 2001
Posts: 4,801
netherlands
Realspawn Offline OP

Expert
Realspawn  Offline OP

Expert

Joined: Jul 2001
Posts: 4,801
netherlands
thank you all i will give it a shot but SED seems to be weird
it gives errors in the last line every time while that line
doesn't even excist. very irritating


Find all my tutorials & Workshops at : www.rp-interactive.nl

Creativity starts in the brain
Re: Play sound only one time on key press. [Re: Realspawn] #373615
06/11/11 13:34
06/11/11 13:34
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
thats might be cause you've forgot to write ";" at the end of some of the function or line.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Play sound only one time on key press. [Re: 3run] #373627
06/11/11 14:14
06/11/11 14:14
Joined: Jul 2001
Posts: 4,801
netherlands
Realspawn Offline OP

Expert
Realspawn  Offline OP

Expert

Joined: Jul 2001
Posts: 4,801
netherlands
nope that isn't it no idea i will try installing again frown


Find all my tutorials & Workshops at : www.rp-interactive.nl

Creativity starts in the brain
Re: Play sound only one time on key press. [Re: Realspawn] #373628
06/11/11 14:15
06/11/11 14:15
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
nope dude, something is in the script, better check it wink


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1