0 votes

I have already an array:

var lines = [acerola, apple, apricots, avocado, banana, blackberry, blackcurrant, blueberry, breadfruit, cantaloupe, carambola, cherimoya, cherry, clementine, coconut, cranberry, durian, elderberry, feijoa, fig, gooseberry, grapefruit, grape, guava, jackfruit, kiwifruit, kumquat, lemon, lime, longan, loquat, lychee, mandarin, mango, mangosteen, mulberry, nectarine, olives, orange, papaya, peach, pear, persimmon, pineapple, pitanga, plantain, plum, pomegranate, prune, pummelo, quince, raspberry, rhubarb, sapodilla, soursop, strawberry, tamarind, tangerine, watermelon]

how can I display all the fruits that started with the letter I choose from?
I kinda making a wordchain game where the answer should start with the last letter of the previous answer. It's for our research so can you please help me!

in Engine by (27 points)

1 Answer

0 votes
var letter = "a"
var possible_answers = []
for answer in lines:
    if(answer[0] == letter):

This will create a new array called possible_answers that contains all members of lines that begin with the letter "a". It loops through all members of lines, checks if they begin with the desired starting letter, and if so, adds them to the array possible_answers.

by (172 points)

thank you very much

Why am I getting "Invalid get index "0" (on base:'String')??
please help me!!

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.