Using a timer to end an experiment

I have made an experiment using the builder that contains 7 routines. Each routine has a criteria to move to the next. However, I would also like to add a timer to the whole experiment so if they don’t complete the whole thing in an hour, it exits but the data still saves.
This seems like an easy problem to solve but I am having a hard time figuring out where in the experiment I would add code for this? At the beginning or end?
Any advice would be greatly appreciated.

Hello,

you need to start the clock at the begin of the experiment and then it depends. Do you want to end the experiment after a loop, a routine or within a trial?

Best wishes Jens

Hello,

I’m trying to have it just end at any point the participant is at after a total of 60 minutes. So either they go through all of the tasks by meeting criterion of 80% in their last 20 trials OR if they haven’t gotten to the end of the experiment within 60 minutes. I have the trials to criterion set up, but not timer/clock.
Not sure if this helps, but this is how I have the experiment set up currently.


Hello,

start a timer at the beginning of the experiment and add your break-condition at the end-routine tab of your relevant routine(s). Test your timer with, let’s say, 1-2 minutes time-out.

Best wishes Jens

1 Like

Hi I’ve tried to add a timer to the beginning of my experiment so that people only have 5 minutes to work on a task before switching to the next and keep getting this error

Alert 4210:JavaScript Syntax Error in ‘Begin JS Routine’ tab. See ‘Line 3: Unexpected identifier’ in the ‘Begin JS Routine’ tab.
For further info see 4210: Probable syntax error detected in your JavaScript code — PsychoPy v2021.2.4

I put this startTime = new util.Clock(); in a Begin Experiment tab before my trials

I am totally new to coding and completely lost, I have to put the study up online on pavlovia so I’ve had to switch everything over to java and online didnt like my old clock I used

Hello,

clock needs manual translation. Usually PsychoPy translates everything to PsychoJS to run offline and online (Code type auto). Set the Code type to both and edit the JS-side. It looks like you did this but not in the proper manner. Your manual editing resulted in incorrect JS. See wakecarter’s crib sheet on how to solve those problems.

When you try to push (sync) the experiment to Pavlovia, you should see an error in the Runner window in your case.

BTW, it is best to open a new thread after it had been “solved”.

Best wishes Jens

much appreciated, new to the forum and I understand there’s best practices. I managed to figure out a work around for the JS based on your advice. Thank you!