Cant index picture in image component

I am trying to simply show an image from an excel file, but the image’s index is determined by a variable. Specfiically, I have a var that selects a random integer, and I want the image component to show $image_column[random_int] . Is there a way to do this ?

Uploading: Screen Shot 2022-03-16 at 11.28.34 AM.png…

To clarify. Are you trying to randomly select a column? When I do this I use a set of if statements, e.g.

if ncode == 1:
   thisImage = image1
elif ncode == 2:
   thisImage = image2
elif ncode == 3:
   thisImage = image3

not a column but a row. My file has a column called “objects”. The x list in the code_4 component represents the possible rows an image will be drawn from. In the image component, Image is set to $objects[ncode] , but it gives me the error : can’t find path / random number from ncode that was selected, as if it is ignoring $objects

To access a particular row of a spreadsheet, add a loop with Selected Rows of selectedRow where

selectedRow = str(ncode-1)+':'+str(ncode)

you’re a genius, thank you!!!

What if selectedRow chooses the row on the first trial of a block. Is there a way to make it so that the subject’s choice on the last trial is what selectedRow equals? My code, e.g., is if key_resp == ‘1’, then ncode = 15, so that for the next trial, selectedRow = 15. This doesn’t even work across trials (the same row is selected in trial2 as in trial1), so at the beginning of trial 1 I added ncode2 = 0, and at the end, if key_resp == ‘1’, then ncode2 = 15, and weirdly, for trial2 selectedRow is updated. But, now when a new block is created, selectedRow won’t update (for the first trial of each block, the first trial of block1 is shown).

What is the minimum value of ncode? I assumed it was 1, which is why I started with ncode-1.

I’m not sure of the rest of your question. selectedRow (my variable) can’t be 15 but it could be ‘14:15’. The selected rows in a loop can’t be changed during the loop, only before it, but can change between repetitions of an inner loop.