The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

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!!

in Engine by (27 points)

1 Answer

0 votes
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

if(input_exists):
    pass # This will execute if the user input was found in lines
else:
    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: https://docs.godotengine.org/en/3.1/getting_started/scripting/gdscript/gdscript_basics.html#for

by (174 points)

thank you very much

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 Frequently asked questions and 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 [email protected] with your username.