| Reference | Downloads | Github

Skipping A Loop

Here is a picture of my experiment sequence for reference:

Currently my experiment runs as is, which is a great start. The next thing I need to do is to have the ‘Popup_Loop’ run conditionally. I currently have the Loop run based on the condition file (which is working), but this means that it is attempting to run the loop during every run of the ‘Trial_Loop’. I only want the ‘Popup_Loop’ to run when the value of a variable in the condition file is 1, not when the value is 0 (i.e. run Popup_Loop when variable Popup_Presence = 1. Do not run Popup_Loop when variable Popup_Presence=0).

From what I understand, I think I need to add a code component before the Popup_Loop (I’m thinking at the end of the previous ‘Email’ routine, but unsure). I really know nothing about coding in Python and I have no idea how to make this happen so that it will skip the entire loop if the value is 0.

I have attempted to insert the following code, adapted from the BranchingExp demo, but it isn’t working. There is no error that occurs; the experiment still runs fine, but it does nothing to skip the Popup_Loop. The experiment runs as if this code didn’t exist at all.

I am wondering if this is happening because PsychoPy doesn’t recognize my variable ‘Popup_Presence’ as a variable. This variable is defined in my conditions file, which is then referenced in another file to divide the trials into blocks. The only reason I am skeptical of this is because other variables are recognized in this way for images, etc.

All help is appreciated!

Hi, this code looks reasonable. Are you making sure to then use this variable for the nreps within the Popup_Loop properties. Within the nrep field (I think thats what the field is called), you would set it to $nPopup_Loop.
Otherwise this code is just running, definint the variable, and then nothing would actually come from it.

No, I absolutely was not doing that, because it didn’t occur to me (oops). I have since added nPopup_Loop to the nReps field. I also realized that the first line of the code was incorrect --> since 1 is a number and the actual value I’m looking for, it should not be in single quotations. Using ‘if Popup_Presence==1:’ and adding the variable to nReps, it works.

This leads me to a new problem, though. The Popup_Loop is now in a 20-trial repeat when nPopup_Loop is used in the nReps field in the loop properties. This kind of makes sense to me because the Trial_Loop is set to repeat 1x, and the Conditions are defined by $Blocks, which is a variable in the condition file. There are 20 rows in each Block file, so I think I get why the Popup_Loop is repeating 20x. Do you know how to get the Popup_Loop to repeat only once, and have the Trial_Loop repeat 20x?