Problems with masked self paced reading task

Hi everyone,

I’d like to run a masked SPR task using 1.82.01 version (Win 10).

The overall procedure is as follows:

    Instructions  --> practice trials --> experimental trials

In each trials, fixation (during 2ms) will be followed by the presentation of trial sentence, comprehension question, and possible answers.

During the experiment, participants will be required to press ‘space bar’ to move on to the next step and to press the assigned buttons to answer the following question.

Since it is the first time to use Code component to run the experiment, I looked up several posts already uploaded in Coding category and found relevant one How do I get Moving window presentation in self paced reading task?

This post is almost the same as my experimetal design in that language used in the experiment is Korean and the aim of this study is to do a masked SPR task using a moving-window presentation.

Unlike this post, I used two separate Condition excel files – one for practice trials, the other for experimental trials – and each sentence consists of 7 words/segments.

So, I just manipulated some codes based on the instructions.

First, I changed the label of x.split() as sentencePrac.split() in Begin Routine because I set the variable as “sentencePrac” for practice items in Excel file.

Additionally, I input the number of segments in a sentence (i.e.,6) like this:
elif wordNumber==6: in Begin Routine
if wordNumber == 7: # the total number of words in a sentence is 7 in Each Frame

However, error messages popped up before presenting practical trials.
What’s the problem and what should I do?

Best,
Lily.

Give us the error messages…

But also remember that Python counts from zero, so if there are 7 words, they will be numbered from 0 to 6.

Oh, so sorry! I forgot to tell you error messages

Error message is like this:
error%20message

For your reference, I attach image files depicting one of Loops I made (All sequences/loops are the same except for the content).

And for Code component,

[Begin Routine]

sentenceList = sentencePrac.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 
    elif wordNumber==6: 
        dashSentence = dashSentence + ' ' + word + '.'# the last word (when the total number of words is 7) will appear with a period
    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 ‘-’.

in Excel file, the total number of words in a sentence ranges from 6 to 10, so multiple ‘elif’ funcitons were used to cover this range

Use the actual name of your Builder text component here:

text.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.

# remove any keypresses remaining in the buffer from 
# before  this routine started:

[Each Frame]

keypresses = event.getKeys() # returns a list of keypresses

if len(keypresses) > 0: # at least one key was pushed
if ‘space’ in keypresses:
thisResponseTime = t # the current time in the trial
wordNumber = wordNumber + 1
if wordNumber == 7: # the total number of words in a sentence is 7
thisExp.addData(‘word’ + str(wordNumber), thisResponseTime - timeOfLastResponse)
timeOfLastResponse = thisResponseTime
continueRoutine = False
elif wordNumber < len(sentenceList) + 1:
if wordNumber == 0: # need to initialise a variable:
timeOfLastResponse = 0
# save the inter response interval for this keypress,
# in variables called word0, word1, etc:
thisExp.addData(‘word’ + str(wordNumber), thisResponseTime - timeOfLastResponse)
timeOfLastResponse = thisResponseTime
# update the text by masking all but the current word
text.text = replaceWithdash(sentenceList, wordNumber)

elif 'escape' in keypresses: 
        core.quit() # I think you'll need to handle quitting manually now.

As I said already, I set a variable for practice sentences as “sentencePrac” to create practices Loop. For this reason, I changed sentenceList = sentence.split() to sentenceList = sentencePrac.split().

Please let me know If there is something wrong.
Thank you so much.

The error tells you that you are trying to refer to something called text, which is not a name that has been defined.

Looking at your screenshots, your text component seems to be called text_prac_trial, so in your code component, try replacing text.text with text_prac_trial.text

The problem is solved!

I really appreciate your help :slight_smile:

Based on your instructions, I finished building the program and it went on pretty well.

But another problem popped up: some words within the sentences (trials) skipped randomly.

I read some threads, but I didn’t find a right solution for that. :disappointed_relieved:

Is there anything that I missed in Code component?