Description of the problem:
I’m trying to create a self-paced reading experiment through PsychoPy which I can run online. Participants would read a sentence one word at a time, and then choose one of two images which best represents the sentence they previously read. Since I’m a linguistics student with little coding knowledge, I’m using the builder.
For the self-paced reading routine, I’ve been through the very helpful PsychoPy Python to Javascript Crib Sheet to help me debug parts of the reading_code component which weren’t translating from Python to JS.
When I run the experiment on PsychoPy it works great, but when I run it through Pavlovia, the image which should appear after the first sentence does not display. A blank screen appears and I have to press ‘esc’ to end the experiment. Before I added the reading_code component to make the sentences appear one word at a time, the pictures displayed normally, so I don’t think this is an issue of where I’ve stored the image files. I’ve also pasted the JS from the reading_code component here:
The space being used to end the previous routine is still down when this routine starts. You need to clear the keyboard buffer, for example in End Routine of your code component.emphasized text
I don’t think image_key is waiting for a space. Participants are supposed to see two pictures labelled A & B side by side (in a single image= stim_image), so image_key corresponds with the picture they choose, ‘A’ or ‘B’. I tried putting the event.clearEvents() function in the End Routine tab of my code component, but nothing seems to change.
In Pavlovia, I turned on the option to receive incomplete results to see whether that would tell me anything useful. When I checked the Excel file, it was blank. So, I think this means that the “word” routine is not ending.
Do you have any other suggestions that I could try?
Okay, I think I’ve narrowed down what the problem is. In the previous code, I did not have a way to end the Word routine, so after the words appeared on the screen, the screen stayed blank.
I looked at related forum posts and attempted to add the last few lines of code to the “Word” routine code component.
I’m not very good at interpreting the JS so please could you show the Python side? It might be that you should use a simpler getKeys. I’m not sure you can use it for the reaction time.
I assumed that len(kb) represented the number of words in each sentence, as word_list= the sentence split into individual words. Because participants must press the spacebar to advance to the next word, I assumed that if I set the function as if len(kb) == 0, that would mean that when word list is depleted, the routine would end. But, clearly I am off!
Thanks for your guidance on this! I changed the code to the following, and it worked!
if len(word_list) == 0:
continueRoutine = False
However, I now have one more issue related to the .pop and .shift functions.
I changed .pop to .shift as the crib sheet suggests, but it still removes the final item from the list. I’ve seen on similar forums that it might have to do with the throw statement in the Javascript translation.
When you said you tried shift, what did that code look like. To work both locally and online in the same way you need a Both component with .pop(0) in Python and .shift() in JS. However, I have no idea what throw means, nor when you need the try/catch since you could just check the length of word_list first.
To be honest, I’m also not sure why the try/catch statements are in there; they were a part of the pre-written code that I found to enable the words to appear one at a time. I can try to take them out and see what happens.
Taking out the try and catch statements in the JS didn’t change anything, and the last item still won’t appear. Should I repost this question under a different topic?