Guide A Beginner To Make A Database For His Card Game

So im basicly - totally new to c# and Unity an i want to make a Pokemon Kinda game, just with collecting cards instead of Pokemon, and for that i need to make some kind of database for my cards.
and also like in pokemon each pokemon can use different moves, so i need some kind of movelist and some way of selecting the possible moves that specific Cards can use.

Ive watched some videos on databases but most of what ive found does not explain it that much so its kinda hard to make something myself out of what im watching. I can only like follow the tutorial and not inventing or implement it like i would have wanted to if i knew how to do it, hope you understand.

i know the obvious answer might be to actually learn the arguments and/or functions and stuff(sorry for the wrong terms but i dont know the right ones). but to those that might say that - i would be grateful if you sent some good links or sources to learn just that!

But for those that might have another answer or tip i would appreciate that greatly as well!

thank you.

Edit: maby important to note the game is for both mobile and pc.

You’re totally new and want to jump into a TCG? Or CCG?

https://www.google.com/search?q=how+to+make+a+tcg+in+unity&rlz=1C1CHBF_enUS906US906&oq=how+to+make+a+tcg+in+unity&aqs=chrome..69i57j0i22i30l2j0i22i30i395l4.3618j1j7&sourceid=chrome&ie=UTF-8

https://www.udemy.com/course/learn-to-code-trading-card-game-battle-system-with-unity-3d/?utm_source=adwords&utm_medium=udemyads&utm_campaign=LongTail_la.EN_cc.US&utm_content=deal4584&utm_term=_._ag_81829991707_._ad_532193842022_._kw__._de_c_._dm__._pl__._ti_dsa-1007766171312_._li_1026873_._pd__._&matchtype=b&gclid=Cj0KCQjws4aKBhDPARIsAIWH0JWUemwnn-mx8MmezfdMPNJTsqYplUHV5Irt68nUc_hFGEQU10pkhDQaAvi7EALw_wcB

One of the failures I usually see in new developers is they have a grand idea and no idea how to get there. Always start small. And use a task management software, Google doc, anything to track your features. There are a ton of free options. But you need to start laying out your game features. Don’t start with “I need to code multiple attacks”, but start with each card only having one ability and then add on other abilities. You’ll struggle more as a new developer to get to the finished product if it is so grand that it appears larger than life.

Databases also aren’t the thing to jump into if you’re new. I don’t know what the tutorials are using, but I remember one tutorial was using scriptableobjects.

2 Likes

I would not go with databases for that kind of thing in Unity. Use Scriptable Objects instead. They are data containers and can reference Unity stuff (Assets, Prefabs) what databases cannot easily.

Edit: typo

1 Like

yeah that is some good advice, im thinking a bit waaay ahead. and yeah ive played a bit with scriptable objects, but im not very sure on how to get information from one script to another. like having some kinda of script where i store information on cards and its “id” then getting that information to the scriptable object that has its own script. ive seen maby 2 videos on that, but still im not able to make that work myself or where to start. i can make a scriptable object where i can manually put in infromation to public floats, text and so on, but that wouldnt work if i wanted to switch between cards or something.
but thank you again for ur advice :slight_smile:

Dictionaries (also called Maps) can be used like a database for your data. Focus on trying to separate your game data from the visuals.

ScriptableObjects would be a good idea for CardData/MoveData, then use Resources.LoadAll to auto-populate the dictionaries from the ScriptableObjects in a certain folder.

Here’s how I might do it. The good part is all this data can be saved/read from JSON.

public class CardData
{
    public string Name;
    public int Strength;
    public int Agility;
}

public Dictionary<string, CardData> CardDB = new Dictionary<string, CardData>()
{
    ["bulbasaur"] = { Name = "Bulbasaur", Strength = 20, Agility = 40 },
    ["pikachu"] = { Name = "Pikachu", Strength = 75, Agility = 90 }
};

// Or with ValueTuples (no CardData type required)
public Dictionary<string, (string Name, int Strength, int Agility)> CardDB2 = new Dictionary<string, (string Name, int Strength, int Agility)>()
{
    ["bulbasaur"] = (Name: "Bulbasaur", Strength: 85, Agility: 40),
    ["pikachu"] = (Name: "Pikachu", Strength: 75, Agility: 90)
};

public Dictionary<string, (string Name, string Type, int Power, int Accuracy)> MoveDB = new Dictionary<string, (string Name, string Type, int Power, int Accuracy)>()
{
    ["tackle"] = (Name: "Tackle", Type: "normal", Power: 40, Accuracy: 100),
    ["growl"] = (Name: "Growl", Type: "normal", Power: 0, Accuracy: 100),
};

public List<(string CardID, string MoveID)> CardMovesMapping = new List<(string CardID, string MoveID)>()
{
    ("bulbasaur", "tackle"),
    ("bulbasaur", "growl"),
    ("pikachu", "tackle")
};

// To use these it would look like this:
void UsageExamples()
{
    // Print out card's name
    var bulbasaurData = CardDB["bulbasaur"];
    Debug.Log(bulbasaurData.Name);

    // Print out bulbasaur's moves (using System.Linq):
    var movesFiltered = (from i in CardMovesMapping where i.CardID == "bulbasaur" select i.MoveID);

    foreach (var moveID in movesFiltered)
    {
        Debug.Log(MoveDB[moveID].Name);
    }
}

this looks interesting, gonna look at it better tomorrow, thank you for your idea :slight_smile:

probably a stupid question, but you have made the Dictionaries Public, in what way would i use the public dictionaries to get the right “Pokemon” information to the Pokemon Object/script that i would use to present them in the game.

lets say i have a image as a Player, and that image has a Character or player/pokemon script that would have all values in it, or at least load them in from the dictionary how would i go about actually get the information like what image to use or what hp or power it has, and so on to the other script. if that is how i should do it. where do i go about finding this out if you think its better for me to read it somewhere rather than you writing me a script lol, but i appreciate an example like u used above, ty alot :slight_smile:

A dictionary stores data in “Key : Value” pairs. Just like a regular dictionary, where you look up a word to find the definition. e.g.

Key: “Book”
Value: “A written or printed work consisting of pages glued or sewn together along one side and bound in covers.”

The dictionary in the example above stores data like this:

Key: Name of Pokemon
Value: CardData object (class)

The CardData class could store any information you want about the Pokemon. You access it the same way you’d use a regular dictionary. You use the name of the Pokemon you are interested in and it gives you the CardData for that Pokemon (as long as you’ve added it to the dictionary).

There are many good explanations of Dictionaries if you google. This one seems quite easy to read and digest:

Just to add - the reason people have suggested Scriptable Objects is that they are great at storing data in the editor. They are assets that you can create and edit inside the Unity Editor.

The Unity Learn tutorials are very useful here:

https://learn.unity.com/tutorial/create-a-character-select-system-with-scriptable-objects

SOs can also be instanced for in-memory only copies of the assets you have in the project. That’s for when you need multiple cards of the same type on the board, but perhaps with different stats. Or you could have a Monobehaviour that takes in an SO for base data but applies modifications at runtime to itself.

The most tough part in the context of SOs would be the save system. Unity can’t serialize dictionaries by default. Unity also can’t serialize collections of scriptable objects. The built in JSON serializer can serialize individual SOs but not a collection of them ie a List assuming is an SO.

I solved that in my project by assigning GUIDs to cards when the SO is created. Then load all card assets from Resources and populate a Dictionary<string, Card>. The dictionary refreshes itself when the game is started, so it’s always up to date. So I simply save a List of GUIDs rather than List of scriptable objects. Then use the ID to look up and retrieve the right SO based on the ID. This way I can change the name of the card and everything else about the card without losing a reference to it.

Thank you for your reply, i will read the links later today