Why am I getting "Invalid index "0" (on base:'String')??

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

I have an array of:

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]

and my script is:

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

then when I run my code it shows "Invalid get index “0” (on base:‘String’)
I am thinking if the editor is the problem because I use the new godot 3.2 Aplha!
Can you please help me!!!

:bust_in_silhouette: Reply From: gruen

Seems, That you forgot To place quotation marks

:bust_in_silhouette: Reply From: Zylann

var lines = [acerola, apple, apricots, ...

This can’t be the real code you used… it doesn’t have quotation marks. Or maybe all of these are variables which in turn contain strings, but you have to tell us what it is.
So if I disregard this completely, my guess would be that your lines array contains an empty string at the beginning.

it comes from a txt file!

Immanity | 2019-10-14 14:25