Need help with words minigame _ newbie

Hi Everyone.

I’m Olayemi and a total newbie with GDevelop. I’m currently learning how to develop games and GDevelop seemed kinda friendly so I decided to start with it.

Here is what I would like to do.
1. Select a word from a list, maybe a file if possible
2. Put the selected word in a Text object
3. Create dynamically as much Text objects as there is letters in the selected word
4. Have a Text object which is updated anytime a letter is clicked
5. Compare the latter text object with the Text object which contains the selected word
6. Send a result of the comparison. Something like ‘This is correct’ or ‘This is not correct’.

Here is what I’ve been able to do so far.
1. Put a fixed word in a Text object
2. Create manually as much Text objects as there is letters in my word
3. Have a Text object which is updated anytime a letter is clicked
4. Compare the latter text object with the Text object which contains the word I put in the first Text object
5. Send a result of the comparison. Something like ‘This is correct’ or ‘This is not correct’.

What I essentially lack is
1. Select a word from a list, maybe a file if possible
2. Create dynamically as much Text objects as there is letters in the selected word

I’ve looked for an answer by searching the posts in the forum but I didn’t find anything that could help me find a way. Maybe I didn’t use the best terms. Maybe it is also because I don’t really know the engine correctly yet. Still, I can’t figure out how to solve this. I feel kinda lost. Can you please help me to find a way ? Thank you.

Easy, to get random words from a file you have to structure the file like this:

{ "Words":{ "0":{ "str":"AWord" }, "1":{ "str":"AnotherOne" }, "2":{ "str":"HowManyWordsDoYouWant?" } } }
As you can see each word is stored in a group with different index, then you can read a random words like this:

Read "Words/"+ToString(Random(2)) from file "myFile.json" and store as text in myWordVariable

Note that I read the group using the a random number converted to string (“0”, “1” or “2” here), this gives a random word.

For the second problem, you have to use the string functions:
First, we will use a loop, so we’ll store the loop index, create a variable “index” = 0

Do = 0 to variable index

Second, a repeat loop, because you’ll repeat the same code multiple times, one for each word, so we have to repeat length-of-the-word times:

Repeat StrLength(VariableString(myWordVariable)) times

Then, inside the repeat loop, you have to create a Text Object at some position (you can use Random or the index variable for a sequence), and the important part, set the Text Object string, the letter at position = Variable index:

Do = StrAt(VariableString(myWordVariable), Variable(index)) to the text of Text Object

Finally, don’t forget to update the index variable, adding 1, so the next loop iteration will get the next letter.

It should look like this:

Hi OlayemiO and welcome to the forum! :slight_smile:

  1. GDevelop supports loading and saving of json files. These are basically text files which you can use like a dictionary.
    There is an article about it in the wiki:
    http://wiki.compilgames.net/doku.php/gdevelop/tutorials/jsonfile
    (If you use GDevelop5, you can ignore the warnings that it only works with HTML5 games since GD5 can currently only create HTML5 games. It just bundles the game together with a striped down chrome browser when you export it as a native application.)
    I would structure the json file like this:
{
    "0": "Hello",
    "1": "World",
    "2": "GDevelop"
}

After you turned it into a GDevelop “Structure” as described in the wiki article, you can use the “Random” expression to pick a random word from the structure. This procedure contains a lot of “behind the scenes stuff”. Check the debug window to see if everything worked correctly. The dynamically created structure should be visible there when the game is running.

  1. Instead of a text object for every letter, you could also use a sprite object and create an animation for each letter. When the image of the letter has a background it is also easier to click on it. Then name the animations “a”, “b”, “c” and so on.
    After that you can place as many copies of the letter sprite on screen as the word has letters. Since the animations are named after the letter you can use the “change the animation (by name)” to show the correct letter and later compare it (“current animation name”) with a letter from the text of you text object that contains the word from the structure (json file).

We need a example in gd for structure variable.
This demand come back often

Sorry to answer so late.
I can clearly see how to proceed now. Thank to you, I can now improve my work.
Thanks a lot for your help :slight_smile:

Thank you for the step by step help. I can clearly see what to do now. :slight_smile:

I didn’t know that I could use another object. I’ll explore that option too. Thank you very much for your help. :slight_smile:

Thank you for your help. I didn’t know that. I’ll do my best to learn more. :slight_smile:

EDIT : :blush: Sorry !! I was in a hurry the other day so I didn’t get what you said.
I think you’re right. It would indeed be really helpul to have that. Especially for newcomers like myself, :smiley: . It will sure come handy.

@OlayemiO, did you completed that game?, I’m new at Gdevelop not just new at Gdevelop new to anything related to programing or engines, I ask you this because I’m trying to do the word game called “Hangman”, but I’m pretty lost, not even know where to start, if you could show me or share your project that will really help me and put me on track if you think that it is possible.

Thanks