Making a word game - Question about label component

#1

Hello, I am currently creating a word game. Basically, it’s a hangman game, there are questions that guide you to the answer.
The game will pick a question and the corresponding answer in a JSON file.
I’ve created a game object with a text component attached to it, which will be tiles appearing on a grid. I want each tile to correspond to a random letter. But that some of the tiles match the correct answer. (omg was I serious ?)
Please refer to the picture below

0 Likes

#2

Double checking: You mean a label component? https://defold.com/manuals/label/

I’m not sure I understand this. What part is random?

In the top section of your screenshot (R*CKY R*AD) you start with a all blank tiles right?

In the bottom part (the part looking like a keyboard) you associate each tile with a letter of the alphabet.

When one of the letters are pressed you check if it corresponds to a letter from the word and in that case reveal it (change from blank tile to tile with the letter).

0 Likes

#3

Sorry, I just realized the concept is a little bit messy in my head. Maybe it’s the reason why I didn’t figure out a solution.

Thank you @britzl yes I meant label component. How to check each letter of a string?

0 Likes

#4

Try:

local s = "defold"
for i=1,#s do
    print(s:sub(i, i))
end
1 Like

#5

thank you, sorry bothering you

0 Likes

#6

Not at all. Happy to help!

If you need to learn more about strings and complex string manipulation there is usually a lot of good resources here: http://lua-users.org/wiki/StringRecipes

0 Likes

#7

thank you for sharing, i’ll definitely check it !

0 Likes