Keep getting this error from custom code component in builder: "IndexError: list index out of range"

Hi all! Really appreciate the help.

I followed Jason Ozubko’s youtube tutorial for adding code components to my builder study in order to randomize multiple conditions across parameters (I have 4 conditions and 3 parameters). I followed the tutorial to a tee and my only difference is the content of my conditions/parameters and that I have 3 parameters instead of 2. Some of my conditions are images as well which I have stored in the excel file labeled as their correct path name.

My experiment runs correctly throughout one iteration of all of the stimuli: one condition from each of the three parameters. Then, during what should be the second round of stimuli it shows the condition from my first parameter and immediately after that I get this error:
image = image_list[curr_item]
IndexError: list index out of range

“image” is my second parameter

I know what this is telling me: that my current image is beyond the list I have provided. However, I simply cannot figure out how to fix this or why it is happening.

What I think is happening is that there is something wrong with my loader component that I placed at the very beginning of the experiment. I added code to print out the 12 words and consistently each time I only get 4 words (my four conditions from my first parameter)

Here is the complete code I get when trying to run the experiment:

Running: /Users/zdamon/Desktop/WDP PsychoPy/WDP PsychoPy_lastrun.py

6826.2711 INFO Loaded monitor calibration from [‘2023_01_05 13:46’]
2023-08-02 22:57:08.059 python[90588:3221357] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to /var/folders/x9/lwmdn6ys3zl_vc5nnntxhnlc0000gv/T/org.opensciencetools.psychopy.savedState
[‘WLP’, ‘RDP’, ‘RLP’, ‘WDP’]
[‘image/sandy2.jpg’, ‘image/sage2.jpg’, ‘image/sandy1.jpg’, ‘image/sage1.jpg’]
[‘arrows/congruentdown.jpg’, ‘arrows/congruentdown.jpg’, ‘arrows/discongruentdown.jpg’, ‘arrows/discongruentdown.jpg’]
9.2422 WARNING Couldn’t measure a consistent frame rate!
Traceback (most recent call last):
File “/Users/zdamon/Desktop/WDP PsychoPy/WDP PsychoPy_lastrun.py”, line 605, in
image = image_list[curr_item]
IndexError: list index out of range
################ Experiment ended with exit code 1 [pid:90588] #################

If you see where it starts inputting the images (image/sandy etc), I don’t see that part of the code until after it has quit.

The loader code has it’s own loop that is set to random and nReps to 1 with my excel file uploaded to the loop as conditions.

In my loader code I have this at the beginning of the experiment:
cue_list =
image_list =
arrows_list =

At the beginning of the routine I have this:
cue_list.append(cue)
image_list.append(image)
arrows_list.append(arrows)

My next routine is a shuffler that has custom code at the beginning of the routine intended to randomize all of the stimuli and print out the order:

#shuffle the stimuli list to create a new order
shuffle(cue_list)
shuffle(image_list)
shuffle(arrows_list)

#debug output for checking
print(cue_list)
print(image_list)
print(arrows_list)

Things I have tried already:
-triple checking that everything is typed correctly in my excel file
-deleting and recreating the excel file (reuploading it as well)
-trying to retype the code to make sure there are no mistakes
-deleting the loop and recreating it
-double checking that nReps in my trial loop is 4 (matching up with the number of conditions)

I am so so so grateful for any help or insight you all could provide!! I suspect the issue is with the loader code so that is all that I am including so that this post doesn’t get extremely long but if you have any ideas about potential other spots where there may be an error I am all ears. Thank you all in advance for your time!

Hello

did you ever checked the value of

Best wishes Jens

Hi! Thanks for your response, I set curr_item equal to my list. I don’t think that is the issue. How do I check the value of it?

Hello zoed

Add a

print(curr_item)

command similar to the

print(cue_list)

that you use.

Best wishes Jens

If you set curr_item = image_list then it isn’t an integer and it will fail

If you set curr_item = len(image_list) then it is too big (valid indexes are 0 to len(image_list)-1 and it will fail.