| Reference | Downloads | Github

PsychoPy Builder Masked self-paced reading experiment with moving forward and back through the text

PsychoPy version
Standard Standalone? (y/n)
What are you trying to achieve?:

I am trying to create a masked self-paced reading experiment which:

  1. Shows an entire paragraph on screen.
  2. Changes all words but the currently read sentence to the letter “X”.
  3. Allows participants to use the ‘down’ key to read the next line of the paragraph and the ‘up’ key to read the previous line.
    3.1 If Participants press ‘Up’ on the first sentence the sentence does not change. If participants press ‘down’ on the last sentence the sentence does not change. For them to advance they must press space but only on the last line ( Line 5)

What did you try to make it work?:

I have used previous topics of discussion as a backbone for this experiment.
For example:


Self paced reading - space doesn’t always move window - Builder - PsychoPy

Both of which have been very useful to understanding how these sorts of tasks are handled in PsychoPy.

From the codes used in these I created a code that I had hoped did both.
My Code is as Follows:
Begin Experiment*

def replaceWithdash(sentenceList, Sentence_Number):
dashSentence = ‘’
for index, word in enumerate(sentenceList):
if index != Sentence_Number:
dashSentence = dashSentence + ’ ’ + ‘-’ * len(sentence)
dashSentence = dashSentence + ’ ’ + sentence
return dashSentence +’.’


  • Begin Routine

Stim_text.text = replaceWithX(sentenceList, Sentence_Number)


  • Each Frame

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

if len(keypresses) > 0: # at least one key was pushed
if ‘down’ in keypresses:
Sentence_Number = Sentence_Number + 1
if Sentence_Number < len(sentenceList):
Stim_text.text.text = replaceWithX(sentenceList, Sentence_Number)
continueRoutine = False
elif ‘up’ in keypresses:
Sentence_Number = Sentence_Number -1
Stim_text.text.text = replaceWithX(sentenceList, Sentence_Number)
elif ‘esc’ in keypresses:


What specifically went wrong when you tried that?:

The way this is currently coded I get Syntax errors which I don’t really see as Syntax errors. From what I understand there are none, but PsychoPy seems to think there are.

As you can see in the code there is currently no IF (sentence_number=len(sentence_list) and if ‘space’ in keypresses. Line to end the experiment.
The reason for this is that when this code is there the experiment runs just fine, only that the welcome text is displayed and then promptly finishes the experiment, data is recorded even though nothing was pressed and no stimuli were presented.

I am going to attach my Stimulus file and Experiment file [Tst2.xlsx|attachment] (upload://tkq8TtdTEGGU2ELGGQSbe0AwbcE.xlsx) (10.1 KB) g.psyexp (11.7 KB)

I am clearly lacking some understanding as to how PsychoPy works so if you know what I have done wrong could you explain to me as though I were a crying child.

Tst2.xlsx (10.1 KB)

Replying with Stimuli file as that didn’t come out right somehow…

The issues have been resolved and I will try to explain what was done in order to do so below.

  1. I was not on the latest version of PsychoPy, as such the Runner wasn’t presenting much helpful information.

  2. Once issue 1 was resolved it became clear that the code "keypresses = event.getKeys() "
    was what was causing the experiment to immediately complete as it didn’t work as I had intended it to on the previous version of PsychoPy (2020.2.4) but does work as I intend it to using PsychoPy (2020.2.8).

  3. The “ReplacewithDash” function borrowed from other experiments and the very useful Works very nicely for experiments that are word by word. In this case the experiment I want to create is to be line by line, I will make changes to this function and post it here when it works as intended. However there is tedious work around i found involving creating versions of each line that are replaced by another character. Something like:

// In the begin Routine Tab
DL_1 = ’ '+ ‘-’*len(Line_1)

WIll achieve this, then simply concatenate the lines you wish to display on screen (in the correct order),
You can then save these various versions and display them based on the current_line which you update every frame like so:

// every frame
if current_line == 0:
PP=DL_1 + DL_2+DL_3+DL_4+DL_5

This is obviously not the most efficient way to go about this but it works.

Also please note that with the “solution” there are various issues with text alignment and spacing. As such adding \n to things is helpful for controlling the spacing of the text.