psychopy.org | Reference | Downloads | Github

Create Stopwatch Pavlovia - starting/ending with keypress

Builder with Code Components
Pavlovia
Operating System Windows 10
PsychoPy v3.2.4

Description of the problem: In my experiment the participants have the task to name pictures on the screen (all displayed at the same time). They have to measure the time they need to do so. Therefore, I included a stopwatch with the code component. It works fine offline (psychopy) but when I upload it, it does not work anymore. I do not get any error messages, that’s why I don’t know where the problem is.

The stopwatch should start when enter ist pressed, display the elapsed time and stop wehen enter ist pressed again. Then I have got a pause, the stopwatch should reset and then it starts over again.
It displays the 0 but not the elapsed time. Sometimes some numbers appear (only very short, not possible to read them).

My python code looks like this:

*Begin routine*

enter = False  # Has enter been pushed?
enterRT = ''  # variable for holding RT
enterClock = clock.Clock()  # Clock for enter bar

*each frame*
keys = event.getKeys()
if not enter and 'return' in keys:  # If enter has not been pushed, reset clock when pushed
    enter = True
    enterClock.reset()
elif enter and 'return' in keys:  # If enter is pushed again, get RT
    enterRT = enterClock.getTime()
   enter = False 

if enter:  # present text on screen after enter has been pushed
    txt_stopwatch.setText(round(enterClock.getTime(), 3))  

My JS looks like this

*Begin routine*
enter = false  // Has enter been pushed?
enterRT = ''  // variable for holding RT
enterClock = new util.Clock()  // Clock for enter bar

*each frame*
keys = psychoJS.eventManager.getKeys()
if (!( enter && 'return' in keys)){  // If enter has not been pushed, reset clock when pushed
    enter = true;
    enterClock.reset();
} else if (enter && 'return' in keys){  // If enter is pushed again, get RT
    enterRT = enterClock.getTime();
    enter = false ;
}
if (enter){  // present text on screen after enter has been pushed
    txt_stopwatch.setText(enterClock.getTime());
}

It does not store the time either, although I added code for that.

*end routine*
psychoJS.experiment.addData('return.rt', enterRT)

Any ideas what the issue might be and how to solve it?
Thanks!

by “I do not get any error messages, that’s why I don’t know where the problem is.” you mean that you don’t see any error in your browser console?

I meant that Pavlovia does not display any error messages. I checked the console too, but it doesn’t display errors either