If this template helps then use it. If not then just delete and start from scratch.
OS (e.g. Win10): Mac Sequoia 15.5 PsychoPy version (e.g. 2024.2.4 Py 3.8): 2025.1.1, using builder mode Standard Standalone Installation? (y/n) If not then what?: yes I think so Do you want it to also run online? (y/n) not needed, however start up is very slow locally, so all troubleshooting has been done online. What are you trying to achieve?: I am attempting to create an experiment that logs the time elapsed for a series of tasks performed by the participant. Only the experimenter will interact with the experiment, and they will press a key to start and stop the timer for each task. Then, the duration of each task will be printed to the log file. Some tasks will have multiple ālapsā where I would need to keep track of the timestamp of multiple button presses.
Currently my experiment is set up so each task has 3 routines: pre test with the name of the task, during the task where the timer is active, and a post task where I would like to display the time elapsed during the task before moving to the next task.
I have two challenges. The most simple is how to get the time elapsed during the task to show on the screen of the post-task routine. I am able to successfully export the duration of this task as keyboardModuleName.rt in the log file. Iāve tried creating a text object in the post-task routine with text print (ākeboardModuleName.rtā) and Iāve also tried a code component inserted at the top of the list of commands in the routine with print(f"Time elapsed for this routine: {t} seconds") entered into the āEnd Routineā tab.
My second challenge would be repeating the above but for a task that has multiple keyboard presses for mutliple laps. I would like to print the time of each lap to the screen as it occurs.
Any ideas on how to print multiple outputs to the screen over time? My other test has multiple laps we need to collect timestamps for. I have the test set up to loop through the laps, and I do successfully record the length of time of each lap in in log file, but I would also like the stop times of each lap to appear on the screen for my experimenter to have as a reference. I have tried using the variable $lapped_routine.stopped in the text field, but I get the error ālapped_routine is not definedā when I torubleshoot the experiment and the experiment stops. I assume this has something to do with my loop but I still am having difficulty figuring it out.
i have some screen shots attached. one shows my flow with the routine in question highlighted with the red arrow. The second shows the layout of the routine, with the module that creates the timestamp highlighted by the blue arrow and the module of code shown in image 3 highlighted by the red arrow. Image 3 has my code.
you can print a variable to the console with the following print-command
print("_40mwt_lapend: ", _40mwt_lapend)
I do not see a routine called lapped_routine in your flow.
I noticed in the flow that you created a couple of routines with similar names, e.g. routine_4MWT1 and routine_40MWT1. It is better to reuse a routine if only the stimuli and some presentation parameters differ from one routine to another. Therefore, instead of using constants, use variables where necessary. See here Wakefield's Daily Tips - #7 by wakecarter
Thank you so much for your reply! Unfortunately, I am having trouble getting that solution to work.
After troubleshooting some more, I believe the issue is how I am defining _40mwt_lapend. When I remove that line, the script runs. Is there a specific syntax I should use when subtracting two variables? Or maybe an issue with where the code is placed?
.stopped is not directly available during the experiment
I would recommend creating bespoke timers with e.g. myClock = core.Clock() and then reading them with myClock.getTime() and resetting them with myClock.reset()
Thanks for the help, and apologies for my delay, I wasnāt getting anywhere and needed to step away from this project for a bit.
Iāve tried to start from scratch to see if I can better understand how to implement the bespoke timers you had mentioned. Unfortunately I havenāt made much progress. Iāve used the resources on your google doc here to the best of my ability, trying to integrate them in a simpler experiment with hopefully less to complicate and mess things up. However, I am still running into issues when I attempt to run the experiment.
I get the following error: āUnboundLocalError: local variable ācoreā referenced before assignmentā
Iāve tried moving the lines:
import psychopy.core as core
import psychopy.event as event
From the ābegin routineā pane to the ābefore experimentā pane of my code snippet, but I am still having trouble. In addition, the script takes nearly 10 minutes to fail and generate an error (if it even starts at all), which I assume has something to do with what I am doing wrong but this makes debugging even more challenging.
I have the file attached as I think that make be an easier way to determine the issue. If you have a moment, could you take a look? I really appreciate your quick responses and have used your responses to othersā questions for help with this as well, unfortunately I just canāt figure this out. I am also open to suggestions for other resources to improve my skills. So far, I havenāt been able to find the solution to my problem in the psychopy doc, other discourse convos, etc likely because I am so new at this and need more foundational information.
Edit: Just a bit more context about the issue with the scriptās delayed start- I downloaded another script that includes a timer from a previous post you had helped with and this loads and runs in a reasonable amount of time.
I edited your experiment such that it at least runs. It might not run in the way you intended. It is not clear to me what the start and stop-keypressed should do.
Thank you very much. The goal of the project is to record the amount of time it takes a participant to perform a test (not on the computer). Just a simple stopwatch. The reason to use Psychopy for this and not an actual stopwatch is that I need to integrate LSL to sync event codes to a recording software we will run during the experiment.
Anyway, I have made progress and can now display the time it took for the participant to complete each lap, but I would like the time elapsed since starting lap one as well just to make things more clear for my research assistants. I am using the ātimeā and āloggingā library.
The task has 10 timed laps. I have 1 routine that is the ālapstartā and one that is ālapendā. I have a loop for ālapendā that gives me the 9 additional laps. Within lap end, Begin Routine I have:
curlap=curlap+1
testName = f'40 meter walk test 1'
MyMess=f"Current Lap {curlap}\n"
for idx in range(0,curlap-1):
lasdur=EndTime[idx]-StartTime[idx]
MyMess=MyMess + f"Lap {idx+1} duration {lasdur}\n"
MyMess=MyMess+"\n Press SpaceBar"
My issue is with how I am defining timeMess/showTime in āeach frameā. I get an error that states:
showTime = CurrTime-StartTime[curlap]
IndexError: list index out of range
To try to trouble shoot I have printed CurrTime and StartTime and it seems like CurrTime is always equal to or greater than StartTime, so I am unsure why it would be out of range. Iām sure this is an issue of me not understanding indexing or something similar within python but I canāt figure it out.
Thank you, I will take a look. Is there an easy way to test the value of curlap at different moments in the experiment? Or would i have to set curlap manually and rerun the experiment with different values to assess this?