What would be the best way to create a ton of different cards in my card game

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MyNameIsntBob

So I’m currently working on creating a card game and stumbled upon the issue that I need to make possibly hundreds of cards for this game, so I was just wondering what the best method would be.
I could go about and create a new game object for each card, but that just seems like the wrong way to do it, (especially because a lot of the cards are going to be similar and I don’t want to recreate the work for each card). So I decided that I’d probably want to have all cards created from a single game object that views a dictionary to decide what it’s properties are. Doing this method I decided it might be easiest to create a JSON file will all of the cards, and just give each card it’s own id.
1: {
“Id”: 1,
“Text”: {
“Body”: “This is the body”,
“Title”: “Title”,
“Cost”: “3”
“Image” : {
“Main”: “res://Assets/CardArtTemplate.png”,
“Background”: “res://Assets/Test.jpg”,
When, however, I try to create this JSON file and import it into the project, it doesn’t seem to work. So I ended up looking into it and people online seem to talk about JSON files as to be used for saving.

Is there a simple way to use a JSON file, or would I need to use a different method to create these cards (possibly have a script that’s just the JSON file)

:bust_in_silhouette: Reply From: jgodfrey

You certainly can use a JSON file for this sort of thing, though depending on your use-case, it may be more trouble than it’s worth.

If the card data isn’t something that needs to be modified outside of the game, then I might just define it directly as a dictionary, in code - perhaps in a singleton script (depending on the required access).

That way, you don’t have write code to find, load, convert the external JSON file to a dictionary before you can use it in your code.

Thanks, I’ll probably try that. So should I just have the dictionary in the card script? or should I have it in the object that’s creating the card, and it passed down the info? or would I just have it in its own script (If I do this way, how would I go about getting the info from this script to the card script)

I’ve never really created a script that isn’t directly tied to a node, and I was actually wondering how I would do that anyway.

MyNameIsntBob | 2020-06-07 21:22

Where you put the script really depends on your overall design and what thing or things might need access to it. If you need to access the information from multiple other places, the easiest think would be to just create it as a singleton. With that, you can reference it from anywhere in your code…

jgodfrey | 2020-06-07 21:34