| Reference | Downloads | Github

Self-paced reading task// A bug in the flow

Hi everyone. My problem pertains to building a word-by-word, self-paced reading task.
Now, everything’s fine, no error, but there is a bug, a pause after each routine.

Look at the flow i built. Every word is displayed in a non-cumulative manner which is totally okay. I have defined the SPACE key for each word. But when a sentence, a routine, is finished, I have to press the space bar, at least 5 times to go to the next routine or sentence.
I’m no expert in coding, I built it from scratch with the drag n drop system of PsychoPy. What seems to be the problem? I’d appreciate your helpful comments in advance. :shamrock:

It sounds like you have extra blank rows at the bottoms of your spreadsheets

Hi. thanks for contributing :shamrock:
you are very right, I noticed that too, but how can I solve it?

I click on insert routine, there’s a dot specifying that routine of mine and I can’t place it any closer to the previous item. Consider the loop I should insert as well.

I’m sorry but I don’t understand this.

How about uploading your spreadsheets and showing screenshots of your loops?

That’s okay. so here’s the spreadsheet for items:

So these are the items - both experimental items and fillers. They should be presented word-by-word in a non-cumulative fashion. There will be comprehension questions asked after each item as well, but it’s a different sheet and because the questions are presented as a whole NOT word-by-word, there’s no problem with that.
My problem: But when a sentence, a routine, is finished, I have to press the space bar, at least 5 times to go to the next routine or sentence. why?

Best regards

Now I can see the issue. You have one sheet for all your sentences.

Your flow is very inefficient since you probably have multiple loops that are nearly identical, except that they point to a different column.

One solution would be to add the correct number of rows to each loop, e.g. Selected Rows 0:20 for a 20 word sentence.

Another would be to use a single loop and put all the word in one column. You wouldn’t be able to randomly present the sentences, but I’m guessing you aren’t doing this anyway.

The way I do this is to have a sentence in each row (in a single cell), split it using code and then present the words one by one within a single routine.

Begin Routine

words=Sentence.split(' ')

Each Frame

if wordNum>oldWordNum:
    phrase+=words[wordNum]+' '
elif myClock.getTime() > readingSpeed * len(words[wordNum]):
    if wordNum==nWords:

This code presented words using a timer (rather than space) with the time proportional to the word length.

I’ve just updated my Code Snippets document with the code for self-paced reading.

Thank you very much for sharing the code. Now, I’m sure that this is the best way but I received an error while doing this, so I watched a tutorial on YT, with JS code. And here’s the code:


And then, I receive this error:

Alert 4210:JavaScript Syntax Error in ‘Each JS Frame’ tab. See ‘Line 10: Unexpected token {’ in the ‘Each JS Frame’ tab.
For further info see 4210: Probable syntax error detected in your JavaScript code — PsychoPy v2021.2

I received the same syntax error for your python code as well. I don’t know what’s wrong though.

I’d be happy to help you debug my code if you show a screenshot of your code showing the error.

Meanwhile, Clock should have a capital C

Very well. Here’s the error I receive from your code:

Alert 4205:Python Syntax Error in ‘Each Frame’ tab. See 'If ‘space’ in keys:
’ on line number 7 of the ‘Each Frame’ tab.
For further info see 4205: Probable syntax error detected in your Python code — PsychoPy v2021.1

if should be lower case (I’ve corrected my code snippet )

The quotes should be dumb (but that might just be from your copy paste – please could you show a screenshot of your Each Frame tab?

sure. and thank you again for doing this. Here’s the whole thing:


now, I corrected the if and typed it up with lower case but now i receive this message and when I run the experiment, only the grey background of PsychoPy is displayed and that’s it!

Oh, here’s the message:
Generating PsychoPy script…

########### Running: C:\Users\ASUS\Desktop\Psycho\ ############
1752.5398 EXP Imported …\Users\ASUS\Desktop\Psycho\target.xlsx as conditions, 5 conditions, 1 params
1752.7238 INFO Loaded monitor calibration from [‘2021_03_18 13:05’]
1752.8487 EXP Imported …\Users\ASUS\Desktop\Psycho\target.xlsx as conditions, 5 conditions, 1 params
pygame 1.9.6
Hello from the pygame community.
13.5872 WARNING We strongly recommend you activate the PTB sound engine in PsychoPy prefs as the preferred audio engine. Its timing is vastly superior. Your prefs are currently set to use [‘sounddevice’, ‘PTB’, ‘pyo’, ‘pygame’] (in that order).
52.4818 WARNING User requested fullscreen with size [1024 768], but screen is actually [1366, 768]. Using actual size
Traceback (most recent call last):
File “C:\Users\ASUS\Desktop\Psycho\”, line 111, in
Wlc_text.setText('Welcome to the experiment.\n\nPress SPACE to continue. ')
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\visual\”, line 374, in setText
setAttribute(self, ‘text’, text, log)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\tools\”, line 141, in setAttribute
setattr(self, attrib, value)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\tools\”, line 32, in set
newValue = self.func(obj, value)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\visual\”, line 365, in text
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\visual\”, line 389, in _setTextShaders
multiline=True, width=self.wrapWidthPix) # width of the frame
File "C:\Program Files\PsychoPy3\lib\site-packages\pyglet\text_init
.py", line 462, in init
‘align’: align,
File “C:\Program Files\PsychoPy3\lib\site-packages\pyglet\text\”, line 604, in set_style
0, len(self.text), attributes)
File “C:\Program Files\PsychoPy3\lib\site-packages\pyglet\text\”, line 512, in set_style
self.dispatch_event(‘on_style_text’, start, end, attributes)
File “C:\Program Files\PsychoPy3\lib\site-packages\pyglet\”, line 418, in dispatch_event
if handler(*args):
File “C:\Program Files\PsychoPy3\lib\site-packages\pyglet\text\”, line 1073, in on_style_text
File “C:\Program Files\PsychoPy3\lib\site-packages\pyglet\text\”, line 1043, in _init_document
File “C:\Program Files\PsychoPy3\lib\site-packages\pyglet\text\”, line 966, in _update
lines = self._get_lines()
File “C:\Program Files\PsychoPy3\lib\site-packages\pyglet\text\”, line 942, in _get_lines
glyphs = self._get_glyphs()
File “C:\Program Files\PsychoPy3\lib\site-packages\pyglet\text\”, line 1085, in _get_glyphs
File “C:\Program Files\PsychoPy3\lib\site-packages\pyglet\font\”, line 394, in get_glyphs
self.glyphs[c] = glyph_renderer.render(c)
File “C:\Program Files\PsychoPy3\lib\site-packages\pyglet\font\”, line 444, in render
gdiplus.GdipGraphicsClear(self._graphics, 0x00000000)
OSError: exception: access violation writing 0x000002EAC9677A40

Experiment ended.

You currently have a text component called text which is set to $target each repeat. What is target?

My code is looking for a variable called Sentence and is trying to update a text component called text_2

I can’t see any evidence of either of them existing.

Well, as you had mentioned before,
I tried to put all the sentences in one column. Of course this is not complete, I was just testing. so should I change the name ‘target’ to ‘sentence’ maybe?

You can change target to Sentence in your spreadsheet or Sentence to target in my code.

text should be set to a single space and constant

text_2.text should be changed to text.text in the code

hi again
I did what you said. But I don’t get what you said in the second line.

what do you mean by a constant? and a single space in the text?

Your text properties currently say text $target and to the right of that you’ve put Set every Frame.

This will attempt to show the whole sentence every frame which will conflict with the code to add a word after every spacebar press.

It should be blank and constant. However, there’s a bug in PsychoPy which gives an error online if a text component is blank so the easiest alternative is to enter a space.

Python.psyexp (10.5 KB)

I changed that thing to constant,
I entered a space in the text box,
modified the code,
still not working. So I figured I share the file for you to see what’s wrong. When I run the experiment, it shows the grey background of PsychoPy and even the system stops working!
I really appreciate your help and sorry that it took so long.

Sorry but I get an error “TypeError: Can’t represent a Param of type color” which I think may be related to " WARNING Parameter ‘contrast’ is not known to this version of PsychoPy but has come from your experiment file (saved by a future version of PsychoPy?). This experiment may not run correctly in the current version."

I’m using 2020.2.10 still.

I’m not sure it’s a good idea to call your experiment and Excel file Python.

What error message are you getting?

yeah, I assume I downloaded the latest version of PsychoPy.
There’s no error. But when I run it, my laptop locks up. I don’t have a very powerful CPU, but I didn’t face this problem when running the experiment with that Java code or that inefficient flow of mine. It’s weird.

ps: As for the name of the file, yeah I know. It’s just that I have three outputs and I wanted to differentiate them from one another. Now, I’m just testing things.

Isn’t there any easy way to do this? :slight_smile: