Player can't click Area2D after clicking it once before?

Godot Version

4.6.2

Question

I’m working on a deck building/deck management game in Godot. It’s been going really well so far, but I can’t get around a hurdle: I can’t seem to click the same area (the same card shape) again, after clicking it once before. I’ve checked that there’s a collision shape, that nothing is in front of it, etc. I can’t find any reason why it won’t click the card shape the second time. Has anyone had a problem like this, and how did you solve it?

First card that gets clicked (“slugly03”):

Code to reveal and click on second card:


func _on_area_2d_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
	if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
if card_title == "slugly03":
				game.hand.erase($CardID.text)
				game.discard_pile.append("slugly03")
				game.empty_slot = 1
				game.itemscript = 0

	if game.itemscript == 0:
				$HandFan/SluglyDeck2/ItemCard1/CardID.text = new_card
				game.hand.append(new_card)
				$HandFan/SluglyDeck2/ItemCard1.show()
				if new_card == "slugly01":
					$HandFan/SluglyDeck2/ItemCard1/Item.text = "Infuse Item"
					$HandFan/SluglyDeck2/ItemCard1/Item/Fullness.text = "Choose an item to \ninfuse. Then discard a\nfood item. The food's\nfullness effect and 1 \nlevel are added to \nthe chosen item."
				elif new_card == "slugly02":
					$HandFan/SluglyDeck2/ItemCard1/Item.text = "Take a Nap"
					$HandFan/SluglyDeck2/ItemCard1/Item/Fullness.text = "Brings your fullness\nback up."
				elif new_card == "slugly03":
					$HandFan/SluglyDeck2/ItemCard1/Item.text = "Back-Up Plan"
					$HandFan/SluglyDeck2/ItemCard1/Item/Fullness.text = "Draw 1 card."


It’s correctly showing the second card, but not allowing the player to select it or interact with it.

Without seeing your code or your node structure, we probably can’t help you.

Does the problem occur only when the card is already selected or can’t you click a card once, another card once and then the first card a second time?

Do you have some bool like currently_selected that you set to true when selected and then forget setting to false?

Do you tie whatever you want to happen to if the card is selected or not?

I’ve added some code in case it helps.

The second card won’t select, regardless of whatever you select before you click on it. Clicking on another card doesn’t help.

I don’t think I have a bool like that set up.

If the card is selected (Area2D is clicked), it’s set up to do whatever is displayed on the card.

I believe that one of the problems could be that you set new_card to what it already is ($HandFan/SluglyDeck2/ItemCard1/CardID.text = new_card) before you use it. So if new_card is slugly_02 and you pick up slugly_03, you will still reuse slugly_02 you picked up previously. You don’t actually change it.

There are also many other weird things.

Here, you set game.itemscript to 0 if the card title is slugly03, and the second if can only run of game.itemscript is 0.

You also put the second if-statement inside the first one. Or it is just how it looks after copy pasting it in here. If the second if is inside the first if, it will not run for any of the other cards, since the first check filters them out.

I can’t see anything that has to do with functionality, only appearance. You set the text and title of the card, but that is all.

You reuse the same node for all the cards. All of them are ItemCard1. You just change the text and title. Unless you do that elsewhere in your code?

If i were you I would look at some tutorials on how to make card games. Like different ways to approach various problems, and then pick the ones you feel will suit you. I think it would be more helpful for you the get a good foundation than doing patchwork on what you have here. In the end you will probably save a lot of time you’d otherwise have spent on bug fixing etc.

Thanks for the detailed reply!

I’m doing my project a disservice by trying to post it here. There’s too much to try to explain and too much code to share. I’m going to just keep working at it until I figure it out.

If it’s an area then every other control node will be “in front” of it in respect to input processing, even if those controls appear to be “behind” in the scene tree. Physics object always receive input events last, regardless of where they are in the tree. Better to use control nodes instead of areas for capturing input.

I ended up switching to a system where the cards are controls in the game, rather than just sprites with data pasted over them. If that makes sense. Anyway, so I’m redoing the project entirely, but it’s going well! Thank you for your suggestion to look into different ways to make card games.