Database help

Hi all. I am using gdevelop to make a mobile tablet game for helping paraplegic and tetraplegic kids in their rehabilitation therapy. The game is in part a card game where the player can get a random card at each turn and there is the problem:
Ho can i make a database containing all the card, with, for each record, the Image, the name, the power level, so i can pick a random record (card) and display all the info related to it in the right areas of the game interface?
Since the game will have hundred of cards, the best for me culd be an excel file with rows and columns but as far as i know is it impossible to use it with gdevelop (but i can be wrong).
Do you have any suggestion? I really appreciate any help you can give me, thanks in advance

To setup databases is not an easy task in GDevelop and maybe I can’t give you a working solution right now, but I try to share some thoughts that may (or may not) help to find a working solution. If anyone else got a working or better solution, hopefully going to share it…

By default, GDevelop is able to store information inside groups, inside txt files like so:

<?xml version="1.0" encoding="UTF-8" ?> <groupname value="0.000000" /> <groupname texte="this is a text" />

So, what I would try to do but I may need to think this through a few more times to get it right is to store the card details in a txt file with all the information of the cards like so:

<?xml version="1.0" encoding="UTF-8" ?> <powerofcard1 value="0.000000" /> <nameofcard1 texte="this is a text" /> <powerofcard2 value="0.000000" /> <nameofcard2 texte="this is a text" />

As of the images, what I would do is have them as 100 animation for each card object in the game and each card object would have some object variables waiting for the information to be loaded from the txt files and also an ID variable with an unique value for each card object. The animation numbers would correspond with the card numbers in the txt file and also with the ID variable of the object.
So the “powerofcard1” would be the power of the card if it animation = 1 and ID = 1, powerofcard2 is the power of the card if it animation is = 2 and ID = 2 and so on…

To choose a random card, we could basically choose a random animation to display for each card and we can assign the exact same number to the ID value of the card and using the ID value we can read the information from the txt file to be loaded in to the object variables of the card.

So the logic would be something like this:

For each card, repeat:
    random_number = Random(100)
    Do = Variable(random_number) to the Animation of card
    Do = Variable(random_number) to card.Variable(ID)
    Read value powerofcard + card.Variable(ID) from file "name_of_file" and store it inside card.Variable(power)
    Read text nameofcard + card.Variable(ID) from the file "name_of_file" and store it inside card.VariableString(name)

In case you want to use a card/animation only a single time during the game, you could use a scene variable as structure with 100 child variables to store what card is still in the pack. The child variables would represent the actual cards in the pack they doesn’t need to have value but simply to check if it exists or not. So it would look something like this.

pack.1
pack.2
pack.3

And so on…

Structure variables are somewhat similar to arrays but not as powerful and flexible, you can read about them on the wiki.

So when you generate a random number, first you can check if the number as child of a structure is exists, technically check if the actual card is still in the pack or not. If it is, then set the animation of the card object, read the values and after delete the child from the structure.

For each card, repeat:
     random_number = Random(100)
     If the child Variable(random_number) of pack exists
           Do = Variable(random_number) to the Animation of card
           Do = Variable(random_number) to card.Variable(ID)
           Read value powerofcard + card.Variable(ID) from file "name_of_file" and store it inside card.Variable(power)
           Read text nameofcard + card.Variable(ID) from the file "name_of_file" and store it inside card.VariableString(name)
           Remove child Variable(random_number) from variable pack
    If the child Variable(random_number) of pack doesn't exists
           random_number = Random(100)

Alternatively you can use a while loop to generate a random number until it find one that exists.

While the child Variable(random_number) of pack exists random_number = Random(100) Do = Variable(random_number) to the Animation of card Do = Variable(random_number) to card.Variable(ID) Read value powerofcard + card.Variable(ID) from file "name_of_file" and store it inside card.Variable(power) Read text nameofcard + card.Variable(ID) from the file "name_of_file" and store it inside card.VariableString(name) Remove child Variable(random_number) from variable pack

But it may become an infinite loop when no more child left in the structure, to avoid that you may also need to count the childs using a variable which initial value would be 100 like child_number = 100 and decrease the value by 1 every single time a new card is generated and check this value:

If child_number > 0
     While the child Variable(random_number) of pack exists
            random_number = Random(100)
 Do = Variable(random_number) to the Animation of card
 Do = Variable(random_number) to card.Variable(ID)
 Read value powerofcard + card.Variable(ID) from file "name_of_file" and store it inside card.Variable(power)
 Read text nameofcard + card.Variable(ID) from the file "name_of_file" and store it inside card.VariableString(name)
 Remove child Variable(random_number) from variable pack
 Do - 1 to variable child_number

It maybe way too over complicated and stupid but this is what personally I would try in GDevelop for a card game. I hope it helps to find a solution though.

Hi! thanks for the quick response.
I think i have found a good way to do it. Probably your method is better but a bit complicated for my low skills.
What i have done is adding object variables to every object/card/player (is a sort of soccer game where you have to randomly find players and create a team). Then i made a condition where i pick a random object from a group (ex. goalkeeper) and then i call his specific variables for my purpose. Like: defense, offense, player name etc. It seems to work, and even if it is a bit longer to make, is not complex to manage (except if you need to mass modify all the cards, but i can live with it for now).
I’ll keep you informed and soon will post an example for better explanation

You mean, you won’t need to translate it at some points? :smiling_imp:
Or rethink your game because what works in windows doesn’t work anymore on tablet?

The only “simple” way I found is to create an external event, calling it “dialogs” or “gametexts”, and make it create an xml file out of nothing, so I can access it later.
This way, I don’t bother with export: it will work in windows ou android the same.
And if I need new translations, I just have to copy/paste the corresponding block of events, change the language condition accordingly (ex : 0 = english, 1 = french, 2 = spanish, etc.) and translate it.

hi, for my needs its just enough for now, becouse the fields dont need translation (there is only the player name, and numeric values for attack and defence). And anyway i am making it for my nephew, so probably the game will be never translated.
I know that my method is wrong, but is simple and let me concentrate on other aspect of the game, i really wish to make it as soon as possibile. Anyway ill let you know if my method will lead me on a dead end road (i hope not! :cry: )