I’m trying to make a card game and have the card snap back to a specific position in the players hand if it doesn’t get used. But I keep getting this error and I’m unsure why.
This is basically what I have in the code, it’s just a little bit of it but hopefully the only relevant bit. The variable pos_in_hand is in a separate ‘card’ scene that gets instantiated into the main scene through a manager, and the function is in a node within the main scene.
var pos_in_hand
func update_hand_positions():
for i in range(player_hand.size()):
var new_position = Vector2(calculate_card_position(i), HAND_Y_POSITION)
var card = player_hand[i]
animate_card_to_pos(card, new_position)
card.pos_in_hand = new_position
The error that I keep getting is "Invalid assignment of property or key ‘pos_in_hand’ with value ‘Vector2’ on base object of type ‘Nil’
I’m very new to this and very confused. Thanks in advance!
If someone in another function deletes the object pointed to by card, the reference held in card becomes invalid (as the object is not existing any more) but it doesn’t automatically become null. And OP’s error says the reference is null.
Yes, caught in the strange world of kinda by reference.
You can change the properties of the passed object but you cannot change the object itself.
My mistake.