Self paced reading: Wrong key freezes experiment

Hi all,
I created a self paced reading experiment and everything works fine (now). But one problem appeared several times and I was not able to find a solution yet:
When running the experiment online (on Pavlovia) and pressing accidentally the wrong key during single word presentation (e.g. “j” instead of “space”) the experiment freezes. I guess it has something to do with the code I am using.

In the self pace reading loop I inserted the stimulus Routine with a code component. This is my JS textcode for “Each Frame”:

//Listen for keys
theseKeys = psychoJS.eventManager.getKeys()

n = theseKeys.length
i = 0

//Update stim on spacebar press
while (n > i){

if (theseKeys[i] == "esc"){

} else if (theseKeys[i] == "space"){
    psychoJS.experiment.addData("readingRT", clock.getTime())
    psychoJS.experiment.addData("sentPos", sentPos)
    psychoJS.experiment.addData("word", stimulus)
    psychoJS.experiment.addData("keypress", theseKeys[i])
    sentPos = sentPos + 1
    if (sentPos == words.length){
        continueRoutine = false
    stimulus = words[sentPos]
    i = i + 1


I wasn’t really able to solve the problem but I inserted a bit of code that allows the subjects to also press the keys “f” and “j” (which are the keys they need to answer the questions). I hope that this reduces the probability of accidentally using the wrong key (which would cause the freezing of the experiment).

Hi afiw! I had the same problem and just solved it. I posted the solution in another post (Problem about making self paced reading experiment for online - #5 by BJ_Kim). I hope it helps!

1 Like