Custom code malfunction

If this template helps then use it. If not then just delete and start from scratch.

OS ( Win10):
PsychoPy version (PsychoPy 2020.2.6):
Standard Standalone? (y)
What are you trying to achieve?:
I am trying to end a loop by adding a time condition with costume code " after 60s of the start of the routine the loop should end. the costume code looks like:
timeStart = psychopy.core.getTime()
timePassed = psychopy.core.getTime() - timeStart
if timePassed >= 60.0:
continueRoutine = False
myloopname.finished = True

The problem is that when the flow gets to the costume code it stops the experiment all together. I have got rid off the condition (if) and the subtraction of time and left the gettime() intact (just as troubleshooting measure) but no luck, when the flow gets to getting the time the experiment ends.

Any thoughts?

Is this in Begin Routine?

timeStart = psychopy.core.getTime()

Is this in Each Frame?

timePassed = psychopy.core.getTime() - timeStart
if timePassed >= 60.0:
     continueRoutine = False
     myloopname.finished = True

However, you could just use t and have the following in Each Frame

if t >= 60.0:
     continueRoutine = False
     myloopname.finished = True

Thanks Wakecarter this is better, at least when the flow encounters the custom code, it does not end the experiment. New problem the loop does not stop when t >=60.
Should I (t = core.getTime()) at the beginning of the routine?

and the answer to your question is yes the previous code was in each frame.

t is automatically reset at the start of each routine. Are you trying to stop the routine after 60 seconds or a loop which will have had several iterations. In that later case you need to start a timer (not called t) just before the loop starts.

I think that starting a clock needs a Both code component. Please check my crib sheet.

Thanks for the prompt response.
In the experiment I have 2 routines inside a loop. The loop must last 60 sec and end, meaning that their will be many passes of the loop in 60 sec but when t >= 60 then the loop should stop.

Please check my crib sheet??

In that case you can’t use t

Also you need to issue the end loop command before you end the routine or it won’t be executed

Thanks again I will try your suggestions and let you know if it works.
Thanks again!!

As Wakefield suggests, you need to start a timer just once, on the first iteration of the loop, so that it will span multiple iterations. Do this in the “begin routine” tab of a code component:

if your_loop_name.thisN == 0: # only on the first iteration,
    loop_timer = core.Clock() # start a new timer

Then in the “each frame” tab:

if loop_timer.getTime() >= 60.0:
    continueRoutine = False
    your_loop_name.finished = True

Sorry – I’d forgotten that you’re not trying to run this online.

Michael thanks for your response!!!
when I run your code I get this error “if loop_timer.getTime >= 60.0:
TypeError: ‘>=’ not supported between instances of ‘method’ and ‘float’”
I have search it but did not find a solution. Any thoughts?

Thanks Wakecarter! I applied Michael’s code and I got an error, if loop_timer.getTime >= 60.0:
TypeError: ‘>=’ not supported between instances of ‘method’ and ‘float’, I have searched the meaning of this, but nothing came up.

OK I got it. the getTime needed (), it is working now. I have time it and it is working great!
Thanks everyone, specially Michael, a life savior!!