Hello! I’m using Godot 4.2,
I want to detect when an array changes so i used this hoping that it works the same way as other variables.
var selectedCards = Array():
set(newSelectedCards):
if selectedCards != newSelectedCards:
emit_signal("CardSelectionChanged")
print("Selected cards changed = ", newSelectedCards)
if selectedCards < newSelectedCards:
emit_signal("CardSelected")
selectedCards = newSelectedCards
Turns out it doesn’t work because .append() doesn’t trigger the set function.
How can i work around this?
P.S. Pretty please explain to me in simple words i’m not very proficient with technical jargon.
Edit: I found this solution but i suppose it’s considered “janky”.
func _process(delta):
selectedCardsSize = selectedCards.size()
var selectedCardsSize = 0:
set(newSelectedCardsSize):
if selectedCardsSize != newSelectedCardsSize:
emit_signal("CardSelectionChanged")
print("Selected cards changed = ", newSelectedCardsSize)
if selectedCardsSize < newSelectedCardsSize:
emit_signal("CardSelected")
selectedCardsSize = newSelectedCardsSize