Auto-> JS Code error, self-paced reading task with moving window


I am building a online self-paced reading task with moving window paradigm. Thanks to other people, I was able to find this code to develop what I want for my experiment.

However, when I tried to type these codes in my code component and translate them to JS code, I get this kind of errors repeatedly: /* Syntax Error: Fix Python code */

Upon completing word ‘for’, I get this error. Could anyone help me out of this issue?

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 + '-' * 6 + ' ' # add a string of dash characters 
        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:

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.


your for-loop is

for index, word in enumerate(textlist):

AFAIK, PsychoPy cannot auto-translate this kind of for-loop.

for var in iterable:

however auto-translates. So you have to change your code to run more along these lines:

days= ( 'Mon', 'Tue', 'Wed','Thu')
enum_days = enumerate(days)
# enumerate using loop
for enum_days in enumerate(days):

example taken from Enumerate() in Python

Best wishes Jens

thanks for your help! However, I’m quite curious about the reason why PsychoPy cannot auto-translate this kind of loop since I saw other people using the same code and successfully translate it to JS code.


ask the developers why PsychoPy can’t autotranslate it or the people using the same code how they did it. Are you sure that they ran their experiment online?

Best wishes Jens