How does Audio Works?

Godot Version

4.4

How does Audio work? in talking State i set sound to play if button pressed play() and if relased Stop() but doesnt work i tried to set playing to true then false if released it makes audio only works after i let go of Pressed Key and has to do it again to turn off audio,
i also added a flying sound it works when i press key i set and it supposed to stop playing if im on floor but it doesnt also how to make flying audio onl play if im on State Fly and FlyF state and only stop if character is not on any of 2 states? Heres my code

func _fly_state():
	print("fly")
	if Input.is_action_just_pressed("Fly"):
		$Audio/Fly.play()
	elif is_on_floor():
		$Audio/Fly.stop()
	animated_sprite.play("Fly")
	if Input.is_action_just_pressed("Fly"):
		velocity.y = JUMP_VELOCITY
	elif velocity.x < 0 or velocity.x > 0:
		current_state = States.FLYFORWARD
	elif is_on_floor() and velocity.x < 0 or velocity.x > 0:
		current_state = States.WALKING
	elif velocity.x == 0 and  is_on_floor():
		current_state = States.IDLE

func _talk_state():
	print("Talking")
	if Input.is_action_pressed("EnterCall"):
		if Input.is_action_pressed("Call"):
			print("Call")
			$Audio/Call.play()
		elif Input.is_action_just_released("Call"):
			$Audio/Call.stop()
	if Input.is_action_just_released("EnterCall"):
		current_state = States.IDLE

It looks like you want to play a sound as long as the user presses a key. In your code, you are starting the sound over and over again, which is why you probably do not hear anything.

You need to check if the sound is already playing as well… if it is then do not call play()

# define fly_sound somewhere

if Input.is_action_just_pressed("Fly") and fly_sound.is_playing() == false:
    $Audio/Fly.play()

Works perfectly fine, now how to do the one for Call :laughing: Call sound to play as long as key is pressed until i let go of “Call” key

if Input.is_action_just_released("Fly") and fly_sound.is_playing()

sry but i meant for this code from action pressed call to released

func _talk_state():
	print("Talking")
	if Input.is_action_pressed("EnterCall"):
		if Input.is_action_pressed("Call"):
			print("Call")
			$Audio/Call.play()
		elif Input.is_action_just_released("Call"):
			$Audio/Call.stop()
	if Input.is_action_just_released("EnterCall"):
		current_state = States.IDLE

Perhaps I’m not understanding the question, but you just basically do the same for each sound.

if Input.is_action_just_pressed("Call") and call_sound.is_playing() == false:
    $Audio/Call.play()
elif Input.is_action_just_released("Call")
    $Audio/Call.stop()

ohh i see i did same but without Just pressed just used pressed i guess thats why it didnt work anyway thank you :slight_smile: