Godot Version
4.2.2
Question
In this image, a timer happens that causes a crowd sound, and you have 5 seconds to press a button. But the button just doesn’t seem to be clickable. Another problem is I have the audio stream player stop when the 5 seconds of not clicking the button finishes, but the audiostreamplayer doesn’t stop when the 5 seconds finish. I don’t know whats causing this.
your _init() first line isnt right, looks like you are using connect of godot 3, not godot 4’s signal connect
it should be looking like this:
pressed.connect(ButtonClicked)
the ButtonClicked should be a function in this script
That didn’t seem to change anything. I still can’t click the button, and the audiostream player glitch is still happening too. The button clicking not working isnt showing up as a glitch though.
at the top of your code write
@onready var audio = get_parent().get_node("AudioStreamPlayer")
and use audio
when referencing your $AudioStreamPlayer
eg replace $Game/AudioStreamPlayer.stop()
with audio.stop()
because your problem is the fact that your node is below the root node so get_parent() selects the node above your current node @Qwergin
As an aside, you should be doing that connection in the _ready()
function not in the _init()
function.
There are a couple of pitfalls you can stumble into overriding the _init()
function.
_init()
is a class constructor and if you are not instantiating class instances in code then there is no reason to override _init().
if you want easy fix, it should be just
change the
$Game/AudioStreamPlayer.stop()
to
$"../AudioStreamPlayer".stop()
I added the variable at the top, but audio.stop() just stops all audio. In this code: func _on_timer_2_timeout():
show()
$Crowd.play()
if(m_elapse > 5):
audio.stop()
When the timer2 times out, the audio instantly times out and it just plays the crowd sound and it doesent time out after the m_elapse thing. Also for some reason when timer2 times out it shows a timer on my screen that shows the current time but its covering one of the images so it messes it up, even though I deleted the script that shows a stopwatch of time. And when I click the button, the timer dissapears so im confused on whats happening.
This helped the button clicking problem, thank you!
This is also very helpful, thank you!