0 votes

I'm trying to check if a user types a specific word in LineEdit. I have the word as a value in a dictionary, and I've used the command if word in new_text (users input), but that only check if the users input is equal to the word.

in Engine by (46 points)

2 Answers

0 votes
Best answer

Try these methods of String class

int find ( String what, int from=0 )
Finds the first occurrence of a substring. Returns the starting position of the substring or -1 if not found. Optionally, the initial search index can be passed.

int find_last ( String what )
Finds the last occurrence of a substring. Returns the starting position of the substring or -1 if not found.

int findn ( String what, int from=0 )
Finds the first occurrence of a substring, ignoring case. Returns the starting position of the substring or -1 if not found. Optionally, the initial search index can be passed.

by (2,262 points)
selected by
0 votes

You can try using a Regular expression to match the word in a sentence. I haven't actually used Godot's regex object myself but it does have one.

http://docs.godotengine.org/en/3.0/classes/class_regex.html

Alternatively, you would have to slice the sentence into a new array of words and then loop through each, compare to your dictionary to find a match.

by (76 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.