NameError: name ____ is not defined, self-paced reading task

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): 10
PsychoPy version (e.g. 1.84.x): 2021.2.3.

Dear all,

I am building a online self-paced reading task with moving window paradigm.Following the code snippets others have posted, I am developing an experiment. However, when I try to run the experiment, I get this following error message and I cannot move forward.

sentenceList = sentence.split() 

NameError: name ‘sentence’ is not defined

I realized that this error is quite common in psychopy and people might come across this type of error at some point.
However, I checked several times to make sure that I’ve inserted the correct variable name ($stimulus) in my text component and my excel sheet has the same colum name.

I am stuck at this problem…Is there anyone who can enlighten me?

This is my code component:
sentenceList =stimulus.split()

this breaks your sentence’s single string of characters into a list of individual

words, e.g. ‘The quick brown fox.’ becomes [‘The’, ‘quick’, ‘brown’, ‘fox.’]

keep track of which word we are up to:

wordNumber = -1 # -1 as we haven’t started yet

now define a function which we can use here and later on to replace letters with ‘-’:

def replaceWithdash(textList, currentWordNumber):

dashSentence = '' 
for index, word in enumerate(textList): # cycle through the words and their index numbers 
    if index != currentWordNumber: 
        dashSentence = dashSentence + '-' * len(word)+ ' ' # add a string of dash characters 
    else: 
        dashSentence = dashSentence + word # except for the current word 

return dashSentence # yields the manipulated sentence 

now at the very beginning of the trial, we need to run this function for the

first time. As the current word number is -1, it should make all words ‘-’.

Use the actual name of your Builder text component here:

MyText.text = replaceWithdash(sentenceList, wordNumber)

In the Builder interface, specify a “constant” value for the text content, e.g.

‘test’, so it doesn’t conflict with our code.