My online experiment abruptly halts on the way

Oh, I’m sorry. I made a typo. It should be “stimuli”, not “stimuli_2.” But It seems like it wasn’t a crucial issue. Auto translation from python to Java didn’t work for the python code for Begin routine. So I borrowed JS code from this reference post. That’s why the function definition of replaceWithdash is located at each frame section in JS version.

python code for stimuli: Begin routine

sentenceList = sen_segment.split("*") 
wordNumber = -1

def replaceWithdash(textList, currentWordNumber):     
    dashSentence = ''
    for index, word in enumerate(textList):
        if index != currentWordNumber: 
            dashSentence = dashSentence + "-" * len(word) + "--" 
        else:
            dashSentence = " " + dashSentence + word + " " 
    return dashSentence 

stimuli.text = replaceWithdash(sentenceList, wordNumber)  

python code for stimuli: Each frame

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

if len(keypresses) > 0:
    if 'space' in keypresses:        
        thisResponseTime = t 
        wordNumber = wordNumber + 1 
        if wordNumber < len(sentenceList): 
            if wordNumber == 0:
                timeOfLastResponse = 0 
            thisExp.addData('IRI_' + str(wordNumber), thisResponseTime - timeOfLastResponse) 
            timeOfLastResponse = thisResponseTime 
            stimuli.text = replaceWithdash(sentenceList, wordNumber) 
        else: 
            continueRoutine = False 
    elif 'escape' in keypresses: 
        core.quit() 

JS code for stimuli: Begin experiment

thisExp = psychoJS.experiment;
win = psychoJS.window;

JS code for stimuli: Begin routine

sentenceList = sen_segment.split("*");
wordNumber = (- 1);

JS code for stimuli: Each frame

var _pj;

function replaceWithdash(textList, currentWordNumber) {
    var index, result, word;
    result = "";
    index = 0;
    while ((index < textList.length)) {
        word = textList[index];
        if ((index !== currentWordNumber)) {
            result = ((result + ("_".repeat(word.length))) + "__");
        } else {
            result = (" " + (result + word) + " ");
        }
        index = (index + 1);
    }
    return result;
}

function _pj_snippets(container) {
    function in_es6(left, right) {
        if (((right instanceof Array) || ((typeof right) === "string"))) {
            return (right.indexOf(left) > (- 1));
        } else {
            if (((right instanceof Map) || (right instanceof Set) || (right instanceof WeakMap) || (right instanceof WeakSet))) {
                return right.has(left);
            } else {
                return (left in right);
            }
        }
    }
    container["in_es6"] = in_es6;
    return container;
}
_pj = {};
_pj_snippets(_pj);
stimuli.text = replaceWithdash(sentenceList, wordNumber);
keypresses = psychoJS.eventManager.getKeys();
if ((keypresses.length > 0)) {
    if (_pj.in_es6("space", keypresses)) {
        thisResponseTime = t;
        wordNumber = (wordNumber + 1);
        if ((wordNumber < sentenceList.length)) {
            if ((wordNumber === 0)) {
                timeOfLastResponse = 0;
            }
            thisExp.addData(("IRI_" + wordNumber.toString()), (thisResponseTime - timeOfLastResponse));
            timeOfLastResponse = thisResponseTime;
            stimuli.text = replaceWithdash(sentenceList, wordNumber);
        } else {
            continueRoutine = false;
        }
    } else {
        if (_pj.in_es6("escape", keypresses)) {
            psychoJS.quit();
        }
    }
}