Counterbalancing issues, UnboundLocalError

Hi, I am currently doing my dissertation project replicating Reagh (2016) study and need to counterbalance order of images on a 7x5 grid differently for 2 different study and test phases. For this I have made 4 different csv files (2 for study phase and 2 for test phase) of the different spatial locations and a conditions file for the study and for the test phase. I can successfully counterbalance for one of the cycles. However, if I try and include the other cycle in the same experiment this error appears: UnboundLocalError: local variable ‘trialList’ referenced before assignment. In my inner loop I have set the conditions to be ‘condsFile’ for both cycles and in the outer loops have attached the relevant csv conditions files (e.g ChooseBlockStudy.csv which contains SpatialStudy1.csv and SpatialStudy2.csv and ChooseBlockTest.csv which contains SpatialTest1.csv and SpatialTest2.csv - under the column heading ‘condsFile’). Attached are some images to help explain what I’ve done but it would only allow me to upload two :slight_smile:
Like I said before, it works for the study cycle but not for the test cycle. Any help would be appreciated :slight_smile: