Using a large array for language game

Hello! I want to make a game to learn Japanese, and it’s something like a flashcard game.

My doubt is in the storening of the words to learn, both in English and in Japanese. Since it could easily be about 2000 or 3000 words, how could I store them in the game so that they are displayed randomly?

Would uploading a json and maintaining an array with 3000 words in memory be a lot or would it be completely normal and manageable? Would you have to use an external database compulsorily to make the requests each time?

Thank you!

3000 words in memory won’t be that much - arbitrarily selecting an average of 15 characters per word using UTF-16, you’d use up 180kb of memory. Not a big amount by any stretch of the imagination.

Using a structure would be trickier, because you cannot easily get the key value of a structure.

However, a way of doing what you’re after is to use an array of strings, storing the two words as a comma separated string (e.g. “sun, 太陽”). You then pick a random array element, split the string at the comma to get the English and Japanese words:

This is the Array (prefilled for testing):




And this is the event to pick a random element and extract the words:

2 Likes

That’s great!

I’ll try that system too, thank you!

Is there any function to convert a string separated by commas into an array? For example, if I wanted to have in the array (English, Japanese, Spanish), to be able to quickly access Spanish with array[2]

If you install the Array Tools extension, there’s an action that will split a string into an array of strings given a separator:

1 Like

I guess it would be easier to use an array of structure rather than comma separated values.

That was my first thought too. But how do you get the key value pairing without using a foreach child event? Say for example you want the word and its translation for the 10th entry. How could you easily go about that with an array of structs?

Something like this: Words[Index].English and Words[Index].Japanese?

1 Like

Ah, I was thinking of using the key as one language, the value being the translation.

Your way would allow for the easy addition of extra languages.

So like a normal array but instead of a string (csv) inside, a structure with pairs of variable: value, is that correct? thanks!

Could you load that array somehow through a json or text file? To be able to work with it, instead of directly using the gdevelop interface.

So I have this structure, that will be perfect. But I dont want to populate each line by hand and creating a loooong scroll on the browser.

Is there any way to load a text file (fixed in resources) that Gdevelope could read and fill this Array?

I test with JSON but strictly is not a json structure, Im a bit lost here…

Yes, if you are using it on Windows, MacOS or Linux. If you can provide a snip of the input file, like a screenful of lines, then we can help with the events to load it in.

1 Like

I have to create the JSON and the structure specifically for it to work in that project, at the moment I have the data saved in another way until I know how to structure it here.

But what I want to do is load a text file (in resources, not updateable) and generate an array of structures, to be able to do what we commented.

You don’t have to structure the file in json, but it does help to simplify the loading process.

Yep, and as I wrote, give us a sample of what the input file looks like, and we’ll help generate events to put the data into the array.

Once that is done, you could load the data, save a jsonified version of it and then alter the load events to use the saved json file.

Alternatively, you could save that example from your previous post as json (so then you have the example in a json text file) and then modify your input file to fit that json format so it can be easily loaded into the array.

I have uploaded a screenshot of how the data I need could be in a previous message, but basically for each text I need to save (a word or a phrase) it should have the variables of “kanji”, “hiragana”, “english”, “romaji”.

Somethign like:

[0]
“kanji”: xxx
“hiragana”: xxx
“english”:xxx
“romaji”: xxx
[1]

That’s how you want it in GDevelop, right?

But how is it currently stored in the text file? You mentioned 3000 words. What does the file containing those words look like?

Now is stored on a Google Sheet. One file is one word, and “kanji” is the first column.

Kanji | hiragana | english | romaji

I tried to export to csv and do something with that, but… dont know

So you have over 3000 files? Or do you mean one line is one word?

Sorry, I meant “line” not “file” xD

Each Row is a word, and columns are the categories (kanji, english, etc)

So 3000 rows.

If you can save the words from GoogleSheets into an CSV, then here’s a possible solution.

Add the Array Tools extension to your game. Then get the words into an array of structs using these variables:



And these events:

Note, I’ve created this using the online editor, and can’t load from a file. Instead I copied the text into text editor, and then copy and pasted it into the InputText variable definition.


Result (via debugger):

Remember, instead of Fruit, Colour and Number, you’d have Kanji, hiragana, english and romaji

1 Like