r/godot•
Square_Device2811

Anyway to stop the audio?

help me

extends Control

u/onready var text = $CanvasLayer/ColorRect/Text

u/onready var audio = $Audio

#@export_file("*.json") var jsonsrc = "res://Assets/Scenes/Dialouge/Empty.json"

var scene_script : Dictionary

var current_block : Dictionary

var next_block

func _ready() -> void:

hide()

$CanvasLayer/ColorRect.hide()

func dialog(jsonsrc):

show()

$CanvasLayer/ColorRect.show()

get\_json(jsonsrc)

load\_block(current\_block)

func get_json(src: String):

var jsontext = FileAccess.get\_file\_as\_string(src)

scene\_script = JSON.parse\_string(jsontext)

current\_block = scene\_script\["start"\]

func load_block(block : Dictionary):

text.visible\_characters = 0



text.text = block\["text"\]

if block.has("next"):

	var key = block\["next"\]

	next\_block = scene\_script\[key\]

for i in range(0, text.get\_total\_character\_count()):

	await get\_tree().create\_timer(0.1).timeout

	text.visible\_characters += 1

	audio.play()

func next():

current\_block = next\_block

load\_block(current\_block)

pass

func _input(_event: InputEvent) -> void:

if Input.is\_action\_pressed("ui\_accept"):

	if current\_block.has("next"):

		next()

	else:

		hide()

		$CanvasLayer/ColorRect.hide()

This is my code. It's a dialouge system. I want to be able to play a noise for each character displayed but still be able to stop all noise as soon as the message is skipped. So far this only works if the message is viewed until the end. audio.stop() doesn't seem to work.

Posted Jun 6, 2026, 9:39 PM UTC

13
Loading comments…