How to find a word in a list correctly?

I’ve read this old topic - (Solved) Check if player typed a word correctly (which is in a .txt file containing a word-list)? - #19 by Keith_1357

Still don’t get how to deal with it correctly. I can get a number of word’s position. But how to use it further? For example :

Here i’m checking if a text from a variable “WordGuess” exists in the text list. After i want to add a condition “If the text from the first variable exists in the text list so add this text in a second variable”.

Welcome. What are you trying to make? You can add the variable “WordGuess” to an array and read the list back with a For Each Child event.

image

While Gdevelop claims to be “no code”. It, like most apps of its kind, requires the knowledge of expressions and basic language concepts. I have no idea on your knowledge level. The wiki, examples and tutorials are good places to start.

GDevelop 5 [GDevelop wiki]

Imagine if you have letter objects on a screen. I made a system that allows to connect these letters adding it to a string variable. For example if a player connect objects W, O, R, D, so a variable “WordGuess” = “WORD”.

I have a long list of words (no matter where it exists : variable/text object/event) . I want a player to connect letter objects on the screen to define a variable “WordGuess”. When a player releases a left button the game should check if a word from “WordGuess” exists in that long list of text. If it exists so this word should be added to any other variable letting me to show it on the screen.

Load your wordlist into a string and compare the Guess word to the list String Variable. Make sure the list begins and ends with whatever the separator character is. (like space, comma or newline) Otherwise you’ll get partial word matches. “ree” would match “green” but " ree " wouldn’t match " green ". Make sure the search word also has the characters. See the post you posted a link to.

StrFind returns the position or -1, you can use the compare 2 numbers and do something if StrFind ≠ -1.

image

You said “Compare”. This is the main issue. How to compare? For example we have “Compare two strings” option. What exactly i supposed to write in “First string expression” and “Second string expression”? Your example of comparing with a number is very simple - i understand it but it doesnt give me any thoughts about implementing the main thing i want.

For example, it’s just a simple test to check if WordList has a “WordGuess” . All words in WordList have space at both sides and the needed size. Is Searching a text should be before “=” or after? What Variable out of these should i write on the other side?

You use compare 2 numbers. On one side it’s the StrFind() expression with the list and search word variables. On the other side is -1. It uses the ≠ sign.

If the string is found it returns the position. If is isn’t found it returns -1. So, if it ≠ -1 then it means the word was found.

1 Like

Thank you. After many tries i did find out how to implement it correctly. If anyone in the future needs the same - i had a long text file with word in a column. Notepad++ allows to add any symbol before and after every string. Copy it to your variable.

1 Like