Can anyone help me with figuring out this code? I want it so that if when I click 2 buttons on my scene it sends out the signal good and when I click one of the other 2 it sends out the signal bad.
Without overcomplicating the code, something like that should work. You just need to connect your buttons in the editor to the appropriate exported fields.
signal good
signal bad
@export var button_one: Button
@export var button_two: Button
@export var button_three: Button
@export var button_four: Button
var button_one_pressed: bool
var button_two_pressed: bool
func _ready() -> void:
button_one.pressed.connect(check_good_press.bind(button_one))
button_two.pressed.connect(check_good_press.bind(button_two))
button_three.pressed.connect(bad.emit)
button_four.pressed.connect(bad.emit)
func check_good_press(button_pressed: Button) -> void:
if button_pressed == button_one:
button_one_pressed = true
elif button_pressed == button_two:
button_two_pressed = true
if button_one_pressed and button_two_pressed:
good.emit()
The bad signal does get emitted, but the good signal still doesn’t
Ps. I fixed it with a minor change
signal good
signal bad
@export var button_one: Button
@export var button_two: Button
@export var button_three: Button
@export var button_four: Button
var button_one_pressed: bool
var button_two_pressed: bool
func _ready() -> void:
button_one.pressed.connect(check_good_press.bind(button_one))
button_two.pressed.connect(check_good_press.bind(button_two))
button_three.pressed.connect(bad.emit)
button_four.pressed.connect(bad.emit)
func check_good_press(button_pressed: Button) -> void:
if button_pressed == button_one:
button_one_pressed = true
elif button_pressed == button_one:
button_two_pressed = true
if button_one_pressed and button_two_pressed:
good.emit()
just change the elif button_pressed == button_one to: elif button_pressed == button_two