Here is the link to my code: Elisabeth Slifkin / CyberExternalFactors · GitLab
This is a similar question to Skipping one loop or another, but I figured it was better to ask in a new thread. The general goal is the same as the previous thread, but the way the experiment is structured is different.
This is what my experiment flow looks like:
I know it’s small, but basically I need to run 1 of the 2 outer loops, based on a condition number that’s set in the expInfo fields.
I’ve copied and pasted from my previous experiment (in the linked post), but I’m having trouble because of the nested loops I believe.
What’s happening now:
When running the first loop: I can run the first loop perfectly, but then it runs 1 trial from the second loop before getting to the end of the experiment.
OR
When running the second loop: It runs 1 trial from the first loop before ending the loop and running the second loop perfectly fine.
The way I have it now, I have a code component at the beginning of the inner loops (Trial_Loop_Blank and Trial_Loop_Math) and a code component at the end of the outer loops (Block_Loop_Blank and Block_Loop_Math). If I just put a code component at the beginning of the outer loops (Block Loops), nothing happens and both loops run anyway.
The code for condtion = expInfo[‘condition’] is in the Begin Experiment tab on the very first routine.
I know this sounds confusing, so hopefully the link to my code will help.
I also can’t test offline because I have some code that’s only written for JS.
To not run a loop you need to have nReps as 0 rather than setting the loop to finished after it has started.
@wakecarter does this work when the running of the loop is conditional? In my previous experiment, I have nReps set to 1 and the conditional skipping works.
I use nReps to a variable set to 0 or 1
I’m not sure if this is what you mean, but if I add a code component to the beginning of the outer loop that has:
if condition == 1:
nReps_Blank = 0
nReps_Math = 1
else:
nReps_Blank = 1
nReps_Math = 0
in Python and
if ((condition === 1)) {
nReps_Blank = 0;
nReps_Math = 1;
} else {
nReps_Blank = 1;
nReps_Math = 0;
}
in JS. I have set $nReps of the outer block loops to nReps_Blank and nReps_Math respectively.
I get the error: “TypeError: Cannot read property ‘0’ of undefined” right before one of the loops should run.
*Note: I am running PsychoPy version 2020.1.3 if that helps. I haven’t updated to newer/the newest version as I am actively updating these experiments and I wasn’t sure if things would stop working.
Set both of the variables to 0 before your if statement and then use it to set the correct one to 1
Is this as simple as saying
nRepsBlock_Loop_Blank = 0
nRepsBlock_Loop_Math = 0
prior to the if statement, or is there more to it?
That’s not what you called your nReps variables in the code you showed.
You’re correct. I have since changed them in my program to the ones directly above.
nRepsBlock_Loop_Blank
nRepsBlock_Loop_Math
In that case, yes I think that should remove the error.
That doesn’t appear to have done anything. The same error still persists.
Please could you set your experiment to running, add a few credits and send me the run link so I can look at the error message myself?
I can’t set it to running as I’m on a license through my university and I have to get it approved first. I did make the GitLab repo public however, if that helps.
Okay so I still have no solution for this problem, or reason for why it’s occurring but I’ve been able to successfully avoid the problem by using Qualtrics! I’m basically having Qualtrics assign a condition number and then directing participants to 1 of 2 different experiment links. Hopefully someone can help me figure this out one day, but for now this is working.