In my experiment, the routine that is shown depends on a randomly chosen value that is decided using code at the start of the experiment. There are two main loops in the experiment. The trials_7 loop is the most outer loop which sequentially goes through specific CSV files. The inner loop consists of 12 repetitions. Once those 12reps finish, the entire loop (trials_7)restarts and the next CSV file in the outer loop begins.
The code I initially had:
#shuffle(rand) # randomise its order
current_rand = rand.pop() # extract one entry on each trial
#choose a new number (category) every time the loop begins
for i in range(len(rand)):
This worked great for the first CSV file that is read from the outer loop (trials_7); however when the loop restarts with the second CSV, the experiment ends with an error since the variable (current_rand) empties after the first 12 trials. The goal is that every time the outer loop (trials_7) restarts, the rand=[1,2,3]x4 will reset and thus reset the variable (currrent_rand). I have the number in the list repeating 4x to ensure that each routine is shown 4times before starting the next loop.
What I tried:
trials_7 = 0
if trials_7.thisN == [0,1,2,3,4,5]:
Error: AttributeError: ‘int’ object has no attribute ‘thisN’
I assume you want to compare whether thisN is 0 or 1 or 2 or 3 or 4 or 5. One way it to simplify your logical expression to
if trials_7.thisN < 6:
You could also use
trialNr = [0,1,2,3,4,5]
if trials_7.thisN in trialNR:
. . . .
You also initialise a variable called trials_7 at the beginning of the experiment. But as far as I understand, you also have a loop called trials_7 This does not work. Use unique names. The error message tells you that PsychoPy is referring to the variable you declared at the beginning of the experiment. This variable (object) does not have the attribute thisN. A loop has the attribute .thisN.
Best wishes Jens
Thanks for your reply! For some reason, the fixed amount of numbers ( 4 of each type) works for the first loop, after that it becomes inconsistent (ex: five 3s, two 1s, five 2s). I also tried adding some code to my B1 routine (where the loop begins again) in an attempt to restart the rand list at the end of the routine but similar issue with the inconsistent drawing of the numbers.
It would be helpful if you could tell us what you changed in your experiment based on these suggestions. Did you get rid of the error message?
Regarding your second question, the inconsistent number of repetitions. Once you have created rand, there is no need to initialise it a second time, just shuffle it a second time. It is unclear to us when you are shuffling or re-shuffling your rand list.
Best wishes Jens
I tried implementing the second option and updated my loop name from trials_7 to ChooseCSV:
trialNR = [0,1,2,3,4,5]
if ChooseCSV.thisN in trialNR:
This successfully got rid of the error message but resulted in the inconsistency of numbers pulled from the list rand =[1,2,3]*4. Previously, i had rand=[1,2,3] *4 and shuffle(rand) under the Begin Experiment Tab; however that is what lead to only the first iteration of the loop having enough numbers in the list to pull from. Thanks again!
when you shuffle rand at the begin of the routine, it will be shuffled each time the routine is called. So, you need to shuffle rand before the routine is called.
Best wishes Jens