How to put an error if the text that I type is not in the text file?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Immanity

For example I have an array of

var lines = [acerola, apple, apricots, avocado, banana, blackberry, blackcurrant, blueberry, breadfruit, cantaloupe]

The word I type is “coconut”, since it is not in my array, I want it to show an output of “Incorrect Spelling”. How can I do that?

Also how can I remove the already use name of fruits in the list when it’s been already called or typed then load it again when the game starts again?
Thank you in advance for the help!!

:bust_in_silhouette: Reply From: Bush2Tree
var input = "coconut" # change this line to change input
var input_exists = false
for member in lines: # loop through all members of lines
    if(input == member): # if the member is the same as the input
        input_exists = true  # signal that the input was found in lines
        lines.erase(member) # remove the member from lines
        break # exit the loop, since a matching member of lines has been found

    pass # This will execute if the user input was found in lines
    print("Incorrect Spelling") # This will execute if the user input was not found in lines

The structure for member in array is very useful for working with arrays. See more here: GDScript basics — Godot Engine (3.1) documentation in English

thank you very much

Immanity | 2019-09-15 01:33