Im making a card game like hearthstone

Godot Version

Im in the last version godot 4.7.2

Question

So im making a card game like hearthstone and im pretty new to doing code. im looking to make my cards attack, but for that i need them to check on what board they are and look at each placement (1 to 6) to attack a random enemy

here is how i organize everything :

And my card is going to be on board A or B, and then my code for now :

extends CharacterBody2D

@exportexport var stats: Res@onreadyurce
@onready var vie: Label = $VBoxCon@onreadyainer/degat
@onready var degats: Label = $VBoxContainer/vie
const BOARDS = preload(“uid://01j33dxd87fh”)

func _ready() → void:
if stats:
stats.out_of_health.connect(_on_out_of_health)
update_health_text()
update_damage_text()

func take_damage(amount: int) → void:
stats.health -= amount

func _on_out_of_health() → void:
print(“Character died!”)

func update_health_text():
vie.text = "Vie: " + str(stats.health)

func update_damage_text():
degats.text = "Degat: " + str(stats.attack)

func attaque():
pass # this is for my futur attack func

My recourses for the stats :

class_name stats_card
extends Resource

@e@exportport var max_health: int
@export var health: int
@export var attack: int

signal health_changed(new_health)
signal out_of_health

func take_damage(amount: int) → void:
health = max(0, health - amount)
health_changed.emit(health)
if health == 0:
out_of_health.emit()

I didn’t found anything about scaning or cheking if they are in a node and then attacking so im really lost to how i have to do my code

Thanks for the help in advence

Hi there!

Could you please wrap your code in a code block?
This icon in the editor:
image

Like this ?

Thanks for formatting the code!

I don’t know the game you inspired from , Hearthstone, but if I understand correctly it has different boards of cards and you try to imitate these two boards. Here is what I would do.

As it looks be the image you pasted of the scene tree you have two control nodes called Board1 and Board2. You can check if a node has one of them as its parent.

You are already using resources, which is great practice for Godot projects. The main purpose is to contain data – even though they can also contains functions. It is probably advisable to use a Resource for tracking which board a card is on. Then assigning its visual presentation to the right parent node depending on the data stored in its resource.


Something went wrong here.

yeah i didn’t check the export, i copy into copy so it went wrong xD

So i need to create another resource with a function or something like it to check if it’s the correct one and then apply everything ?