If this template helps then use it. If not then just delete and start from scratch.
Win11
PsychoPy v2021.2.3
What are you trying to achieve?
Hi everyone, I am creating this task and am rather new to programming, so any help would be very much appreciated.
In this task, I have 32 conditions with 5 parameters that are going to be presented to the participant randomly. However, I would like the number of repetitions for the experimental loop to be determined by participants at the beginning of the task.
My code to stop the loop which is positioned in the last Routine of my loop is:
(Begin Experiment)
myCount = 0
(Begin Routine)
myCount = myCount + 1
if myCount >= ntrials:
trials.finished = True
In the code above, the variable ntrials is the number of trials that I want the participant to be able to enter (only once at the beginning), and trials is the name of my loop.
What did you try to make it work?
I have tried two ways to make this work, but I have been unsuccessful in both of them. Feel free to point out the problem with either of my solutions or suggest a more appropriate way of approaching the problem.
- I tried to add a Textbox component and position it in my first Routine (called textbox). I have made the Textbox editable to allow the participant type their response. Then I added a code component to the same Routine with the following code:
(End Routine)
ntrials = int(textbox)
The problem with this solution:
My loop only runs once and it crashes and exits the experiment right at the end of my loop where the myCount code is located.
- I have also tried to use the fields in the Experiment info section as the place where participants determine the number of trials. So, in the settings I added repetition field to participant and session. However, I do not know how to call the data from this field to my loop. I have tried to use this code:
ntrials = int(repetition)
The problem with this solution:
However, the same issue occurs and my task crashes at the end of the first round of my loop without any error (most likely because it cannot access the data in the repetition field, but I do not know how to call that data to my loop correctly).
Again, I would really appreciate your help and suggestions.