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

**URL:** <https://forum.makecode.com/t/bizzare-error-when-concatenating-deeply-indiced-strings-dereferencing-null-undefined-value/17372>\
**Category:** Help\
**Created:** [January 11, 2023, 6:27pm UTC](https://forum.makecode.com/t/bizzare-error-when-concatenating-deeply-indiced-strings-dereferencing-null-undefined-value/17372 "2023-01-11T18:27:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ADVFRED](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/advfred/32/7481_2.png) [@ADVFRED](https://forum.makecode.com/u/ADVFRED)\
**Post date:** [January 11, 2023, 6:27pm UTC](https://forum.makecode.com/t/bizzare-error-when-concatenating-deeply-indiced-strings-dereferencing-null-undefined-value/17372/1 "2023-01-11T18:27:17Z")

</div>

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:

> **[MakeCode Arcade SAT Run - Pastebin.com](https://pastebin.com/fVwL2Z0u)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

Full Program:

> **[SAT Run](https://arcade.makecode.com/S96312-19522-31629-13896)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [January 11, 2023, 6:29pm UTC](https://forum.makecode.com/t/bizzare-error-when-concatenating-deeply-indiced-strings-dereferencing-null-undefined-value/17372/2 "2023-01-11T18:29:20Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![ADVFRED](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/advfred/32/7481_2.png) [@ADVFRED](https://forum.makecode.com/u/ADVFRED)\
**Post date:** [January 11, 2023, 11:02pm UTC](https://forum.makecode.com/t/bizzare-error-when-concatenating-deeply-indiced-strings-dereferencing-null-undefined-value/17372/3 "2023-01-11T23:02:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ADVFRED](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/advfred/32/7481_2.png) [@ADVFRED](https://forum.makecode.com/u/ADVFRED)\
**Post date:** [January 12, 2023, 3:59am UTC](https://forum.makecode.com/t/bizzare-error-when-concatenating-deeply-indiced-strings-dereferencing-null-undefined-value/17372/4 "2023-01-12T03:59:09Z")

</div>

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