My buttons are immediately pressed when running

Godot Version

func _process(delta):
if _on_first_button_pressed():
Global.transition_scene = true
change_scenes(“res://first.tscn”, “first”)
elif _on_second_button_pressed():
Global.transition_scene = true
change_scenes(“res://second.tscn”, “second”)
elif _on_third_button_pressed():
Global.transition_scene = true
change_scenes(“res://third.tscn”, “third”)
elif _on_fourth_button_pressed():
Global.transition_scene = true
change_scenes(“res://fourth.tscn”, “fourth”)
elif _on_fifth_button_pressed():
Global.transition_scene = true
change_scenes(“res://fifth.tscn”, “fifth”)

func _on_first_button_pressed():
return true

func _on_second_button_pressed():
return true

func _on_third_button_pressed():
return true

func _on_fourth_pressed():
return true

func _on_fifth_button_pressed():
return true

Question

I’m trying to make an app and I need to switch scenes on the click of a button, but when it’s run it’s as if the button is instantly pressed and the scene is instantly switched. I’m using the _on_button_pressed connection and when it’s pressed it returns true and in _process, it checks if each _on_button_pressed function returns true, and will then switch scenes, and the switching seems to work.

This is not how these methods work, you just return true, signals don’t work like this

You need to instead have a variable that’s set when pressed, or just check if the button is pressed with the pressed property

Or just put the code for each in the callback, like so:

func _on_first_button_pressed():
	Global.transition_scene = true
	change_scenes(“res://first.tscn”, “first”)

func _on_second_button_pressed():
	Global.transition_scene = true
	change_scenes(“res://second.tscn”, “second”)

func _on_third_button_pressed():
	Global.transition_scene = true
	change_scenes(“res://third.tscn”, “third”)

func _on_fourth_button_pressed():
	Global.transition_scene = true
	change_scenes(“res://fourth.tscn”, “fourth”)

func _on_fifth_button_pressed():
	Global.transition_scene = true
	change_scenes(“res://fifth.tscn”, “fifth”)

The method is called when the button is pressed, it doesn’t give any information, it’s just a method

Ok that makes a lot of sense, thanks.

1 Like

If this solves your problem then please mark it as solved with my solution, that way people know it’s solved

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.