Code to rotate images only works on first trial

Hello. I am using the Builder to create a task where in each trial 2 images side by side are shown. One of them is initially upside down and will rotate to its correct orientation on trial onset (ideally 2s after trial onset). The participant’s task is to report the direction of the rotation of the object using a keypress. I have two issues:

  1. I have code that successfully rotates the target image on trial onset. Unfortunately, it only happens on the first trial. Subsequent trials do not rotate, nor are image positions randomized. I think the entire code component doesn’t carry over to the next routine.

  2. Right now, the rotation is clockwise. How do I randomize this so that in some trials, the rotation is counterclockwise?

***Begin experiment
imPositions = [(-.35, 0), (.35, 0)]
shuffle(imPositions)
Image1P.setPos(imPositions[0])
Image2P.setPos(imPositions[1])

***Begin routine
Image1P.setPos(imPositions[0])
Image2P.setPos(imPositions[1])
shuffle(imPositions)  # to randomize position

currentOri = 180

***Each Frame
if Image1P.ori < 180:
    Image1P.ori += 1
    current0ri = Image1P.ori

I know these are quite basic questions. My apologies. I’m quite new to coding. Any help is appreciated! Thank you so much.

1 Like

To randomise the direction:

***Begin experiment
imDirection  = [1,-1]

***Begin routine
shuffle(imDirection)
currentOri = 0

***Each Frame
if abs(currentOri)  < 180:
    Image1P.ori += imDirection[0]

Put currectOri as the orientation in the component, set to update every frame.

Hi Wakefield! Thank you so much for responding to my query. I added the codes and set the orientation to update every frame. When I run the task, I believe every trial is now updating, however, the direction is either clockwise or static. It does not rotate counterclockwise.

I tried changing the code in the Each Frame tab:

if abs(currentOri)  < 180:
    Image1P.ori + imDirection[0]

This resulted in Image1P rotating in every trial BUT only clockwise. :\

***I accidentally deleted my first reply.

Please could you show your version of the three snippets? In the one you have shown, you’ve put + instead of +=

Begin Experiment
imDirection  = [1,-1]

Begin Routine
shuffle(imDirection)
currentOri = 0

Each Frame
if abs(currentOri)  < 180:
   Image1P.ori + imDirection[0]

Update: Now even with “+=” in the Each Frame code, every trial rotates but only clockwise.

Try adding some print statements to look for errors.

e.g.

print('direction',imDirection[0])
print('orientation',Image1P.ori)

capture_directionerror

It “rotates” 1 and -1 in but in blocks, and when run, it’s still all clockwise.