Hello! im creating a creature card battling game as my first personal project. So far, i was able to create a base generic scene for a generic card. I was also able to create a hand scene to hold multiple generic cards and select between them, but now im struggling to find a way to specify different presets for this generic card including what creature i want displayed and it’s stats.
I wanna be able to set what type of card it is while instantiating it on the hand scene, how could i do that?
(for future plans, i’d like for each creature to have a specific mechanic that alters the way they function in battle besides just different base stats, it would be of great help if the person reading this keeps that in mind to avoid having to re-do large parts of code later on)
You can create a code in the card scene with something like that:
func set_card_parameters(p_dict_parameters: Dictionary) -> void:
# The dictionary can be something like:
# {"card_title": "title", "image_path": "path", "hp": 10,
# "size": 10, "def": 10, "atk":10}
# Now you use the info to set the card, example:
$hp_label.text = str(p_dict_parameters["hp"])
$bug_image.texture = load(p_dict_parameters["image_path"])
To hold the creatures data you can create a static dictonary inside a custom class:
class_name CreaturesDatabase
# You can identify them inside this dict by an id, by a number,
# the card name, etc... That's up to you decide the best way to identify them
static var dict_database: Dictionary = {
"creature_a": {"card_title": "title", "image_path": "path", "hp": 10,
"size": 10, "def": 10, "atk":10},
"creature_b": {"card_title": "title", "image_path": "path", "hp": 10,
"size": 10, "def": 10, "atk":10},
}
And when you create a new card, you can set the card like that:
# Code that instantiate the card
new_card.set_card_parameters(CreaturesDatabase.dict_database["the_creature_you_want"])
Custom Resources!!! I’m building a whole game that’s resources slotted into generic scenes and it works beautifully. It’'s better than the dictionary approach because it’s much more editor and human friendly. The docs page is here, but the idea is that you create a script that inherits from resource rather than node. Be sure to give it a class name, and list out the variables that each of your cards needs (text, art, you can even create an array of callables (that’s where you can store the functions different cards call)). Then in your file hierarchy you can create new resources and edit them. Once you have the resources you can load them into your generic scene and swap them as necessary.
When your data gets big, you can store your info in a spreadsheet then load it into resources.
Edit: This tutorial literally just dropped.
Im pretty sure this is exactly what i need! ill add the solved tag once im able to implement it/am sure its actually what im looking for, but this seems incredibly useful! ill look further into this thank you.
This is the way I define the things I know have the same data types with different values. Resources (.tres) are really good for that. Just define a class that has all the pertinent data structures and assign that to the resource. You get the idea.