Card Text Swapped When Duplicates are in a Deck

Godot Version

4.2.1

Question

The project is a card game. Cards can be modified, in this case by their own effects. The card in question consumes a resource, and tracks how much it has consumed (Labeled “Faith”), and displays that in the card text. When it reaches a sum of 10, an ability triggers. I have encountered a bug where when I have two of this card, each displays the other’s total. Nothing odd occurs when only one is in the deck.

For example, one card displays “7 Faith” and the other displays “3 Faith”. I play the one labeled “3 Faith” with 3 resources to consume. I expect it to go to 6. But the debug command reads that 7 has gone to 10, and the ability triggers as if I had played the one labeled “7 Faith”. This occurs no matter if the other card is also in hand or not.

I am truly baffled how the cards are linked in this way, while still functioning as normal otherwise. The code in question:

func apply_effects() -> void:
	Events.request_gamestate.emit()
	var gamestate = await Events.gamestate
	var money = gamestate[0]
	var food = gamestate[1]
	
	print_debug(money,food, faith)
	faith += money + food
	print_debug(money,food,faith)
	
	Events.add_money.emit(-1 * money)
	Events.add_food.emit(-1 * food)
	
	rules_text = "Lose all Money\nand Food, gain\nthat Much Faith\n" + str(faith) + " Faith"

	if faith >= 10:
		some_function()

The cards are stored as resources, and are added to the deck by this code, if it is relevant. I checked, and they have different object IDs after being created:

func generate_starting_deck() -> void:
	for i in 2:
		deck.cards.append(farmer.duplicate(true))

what is farmer here? a node/scene? or array/dictionary?
dont use “true” on duplicated node, because it means you are just duplicate it with flag 1. read here

It is a custom resource, each one representing a card. It’s loaded into that script like so:

@export var farmer: Card

The name is arbitrary, it’s just the slot I’m using to test new cards as I code them. The “Apply Effects” code is attached to that resource. I’m duplicating them so that they can be modified independently over time.