I'm working on a chess clone. There is a Board node of type VBoxContainer with 8 children holding the board's rows of type HBoxContainer, and each row has 8 children that are instances of a custom Square scene. I want to use the onBoardguievent signal / function to make sure it's code is only ran when mouse input happens within the Board. However, the function does not run at all.
This is the script for the Board:
extends VBoxContainer
var hovered_square : Node
var clicked_square : Node
var held_piece : Resource
onready var Cursor : Node = get_parent().find_node("Cursor")
# Connects each square's mouse_entered signal to Board
func _ready():
for y in 8:
var row : Node = get_node(str(y + 1))
for x in row.get_child_count():
var children : Array = row.get_children()
children[x].connect("mouse_entered", self, "_on_Square_mouse_entered", [children[x]])
func _on_Square_mouse_entered(square):
hovered_square = square
print("entered " + hovered_square.name)
func _on_Board_gui_input(event):
print(event)
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT:
clicked_square = hovered_square
held_piece = clicked_square.piece
print("clicked " + clicked_square.name + ", holding " + held_piece.name)
Is there a way to get onBoardguievent to work like I want, or should I take a different approach to implementing this feature? Also, feedback on general code style / structure is welcome if you are willing to provide it :)