Currently, I’m handling screen taps to start gameplay. I also have a button at the bottom of the screen to toggle sound. Unfortunately, this logic only works partially. Currently, tapping the screen mutes the sound, but the game doesn’t start. What adjustments should I make to the script for the game to function correctly?
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
if $TextureButton.pressed:
if $TextureButton.pressed:
AudioServer.set_bus_mute(audio_bus_index,not AudioServer.is_bus_mute(audio_bus_index))
$Bird.flying = false
else:
$Bird.flying = true
if game_running == false:
start_game()
You probably have set up your if and else statements incorrect.
Why is there 2x TextureButton.pressed?
Maybe write down what you need in pseudo code and then rearrange your code.
For example:
if button pressed
if game_running:
stop game
else
start game
func start game
make bird fly
unmute audio
game running = true
func stop game
stop bird flying
mute audio
game running = false
For the main question, just use the TextureButton.pressed signal instead, don’t make any sense do this in code like that, will just make things harder (see more: Using signals — Godot Engine (stable) documentation in English). Btw this $TextureButton.pressed is the signal and will always be true in the if evaluation, so will not help you as is.
Basically is write the steps of what you need to do instead the actual, like was done in the other commentary, helps organize the thoughts to convert for the true code later.