Bizzare error when concatenating deeply indiced strings, "Dereferencing null/undefined value."

Hello, I’m about at my wits end and would really appreciate some help. The big picture is the player is asked a vocabulary question when the player hits a coin in order to collect the coin. I’m having trouble displaying the question, which is a mash of concatenated text and list indexes.I’m doing the bulk of this code in python, relevant code block below as well as the entire project.

I scaled it back to find the breaking point,
this segement will be displayed:

question=“HI! \n”+WordList[0][0]+“\n”+WordList[1][0]+“\n”+WordList[2]

As will this

question = “Definition of " + WordList[indice][0] + " is:\n”+"1: “+WordList[QuestionIndices[0]][1]+”\n 2: "+WordList[QuestionIndices[1]][1]

but not this, adding a third line of blank text to the previous segment causes the error

question = “Definition of " + WordList[indice][0] + " is:\n”+“1: “+WordList[QuestionIndices[0]][1]+”\n 2: “+WordList[QuestionIndices[1]][1]+”\n”

I frankly have no idea why this is happening and if anyone has som illumination I would be much obliged.

Full relevant code segment:

Full Program:

looks like you have an off by one error in your code:

    WordIndice = randint(0, len(WordList))
    DefinitionIndice = randint(0, len(WordList))

randint is inclusive, so both WordIndice and DefinitionIndice have a chance of being set equal to the length of the wordlist, which is an invalid index. if you subtract 1 from the len, then you should be fine!

1 Like

Ohhh, I can’t believe I missed that! :man_facepalming: I’ll give that a try once I get home. Thank you so much for the help!

1 Like

That did indeed fix it! I really appreciate the help! I haven’t a clue why it was affecting displaying newlines but it thats irrelevant now! :smiley: