# My online experiment abruptly halts on the way

**URL:** <https://discourse.psychopy.org/t/my-online-experiment-abruptly-halts-on-the-way/20039>\
**Category:** Online experiments\
**Tags:** pavlovia\
**Created:** [January 30, 2021, 4:22am UTC](https://discourse.psychopy.org/t/my-online-experiment-abruptly-halts-on-the-way/20039 "2021-01-30T04:22:07Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![Galaxy\_Brown](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/galaxy_brown/32/4577_2.png) [@Galaxy\_Brown](https://discourse.psychopy.org/u/Galaxy_Brown)\
**Post date:** [February 1, 2021, 2:21pm UTC](https://discourse.psychopy.org/t/my-online-experiment-abruptly-halts-on-the-way/20039/7 "2021-02-01T14:21:30Z")

</div>

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](https://discourse.psychopy.org/t/moving-window-code-component-not-working/13210/8). That’s why the function definition of replaceWithdash is located at **each frame** section in JS version.

## python code for stimuli: Begin routine

```auto
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

```auto
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

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

```

## JS code for stimuli: Begin routine

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

```

## JS code for stimuli: Each frame

```auto
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();
        }
    }
}

```

---

_[View the full topic](https://discourse.psychopy.org/t/my-online-experiment-abruptly-halts-on-the-way/20039)._
