How can I limit the clickable area for a button?

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()

If it helps, I used a YouTube tutorial - “https://youtu.be/9f9t9eiCDAA?si=X1wTH9BxsWV2Bh5q”. Thanks in advance!

1 Like

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

I don’t quite understand the workings of your explanation. Can you please tell me in more detail

What I can understand is that he is telling you that there shouldn’t be two if statements:

if $TextureButton.pressed:
  if $TextureButton.pressed:

@trizZzle What is pseudo code? I can’t seem to understand it and neither does @scelcoding

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.

1 Like

I did not know that, thank you!