Godot Version
4.4
Question
Hey, I’m making some highlighting logic for my cards in my game that I’m making, but the code doesn’t seem to be running, and I’m not sure as to why.
This snippet of code is part of my hand script, which keeps track of all the cards and the related functions to them. I am connecting the mouse_entered and mouse_exited signals from my card scene to the handle funcs but whenever my mouse enters the cards, nothing happens. Testing my mouse enter and exit in the card scene does work however, so I’m no longer sure as to what is causing the issue. Edit: The main issue is that, handle card entered is never firing.
# func to add a card to the hand
func add_card(card : Card) -> void:
add_child(card) # add the card as a child of the hand node
cards_in_hand.push_back(card) # push the card into the back of the cards in hand array
# connect both mouse signals
card.mouse_entered.connect(handle_card_entered)
card.mouse_exited.connect(handle_card_exited)
reposition_cards(0.0)
# func to remove the card from the hand. Returns the card removed
func remove_card(index : int) -> Card:
var card : Card = cards_in_hand[index] # get the card from the hand
if card != null:
# disconnect the mouse signals
card.mouse_entered.disconnect(handle_card_entered)
card.mouse_exited.disconnect(handle_card_exited)
cards_in_hand.remove_at(index) # remove card from array
remove_child(card) # remove card as child
else:
push_warning(str(index) + " is not a valid index")
return null
reposition_cards(0.0)
return card
# func to handle the card entered. Pushes the card back in the touched cards array
func handle_card_entered(card : Card) -> void:
print("enter") # test print
touched_cards.push_back(card)
# func to handle the card exited. removes the card from the touched cards array
func handle_card_exited(card : Card) -> void:
print("exit") # test print
if touched_cards.size() == 0:
push_warning("Tried to remove " + str(card) + " from touched cards")
return
touched_cards.remove_at(touched_cards.find(card))
Here are the two signal emittions if that is helpful, these come from the card script. I have an area2d in my scene and I connected it’s mouse enter and exit to these funcs
signal mouse_entered(card : Card)
signal mouse_exited(card : Card)
func _on_mouse_entered() -> void:
mouse_entered.emit(self)
func _on_mouse_exited() -> void:
mouse_exited.emit(self)
Testing these funcs in the card scene does work, I’ve tried a lot of things to get this to work, so now I’m at a loss. If you need anymore info please ask :D.
