Randomise location in builder / psychopy handling arrays

I’d like to refer to locations by variables so I can shuffle them across trials.

Code for beginning of routine:

import random

loc1 = (-.4, -.3)
loc2 = (.4, -.3)

locs = [loc1,loc2]

# we skip this for now:

thisExp.addData("locs", locs)

And then for position variable:

I get the error message:

GL.glTranslatef(self.posPix[0], self.posPix[1], 0)
IndexError: index 1 is out of bounds for axis 0 with size 1

Same result with $locs[0] instead of locs[0].

This suggests there’s something wrong with how psychopy reads the array or how variables are passed along. When I try the code in a python interpreter, print(locs[0]) works fine.

You can have a try like this:
loc1 = (-.4, -.3)
loc2 = (.4, -.3)

locs = [(-.4, -.3),(.4, -.3)]


1 Like


one way to select randomly from two positions is to create two lists, one your your x-coordinate, the other you your y-coordinate. Shuffle each and use those to create your position.

Begin experiment tab

loc1 = [-.4, -.3]
loc2 = [.4, -.3]

Begin routine tab

thisExp.addData("posx", posx[0])
thisExp.addData("posy", posy[0])


Best wishes Jens

1 Like

In the end I shuffled the text strings, not the positions.

targets = [target1,target2] # where target1,target2 are cols in the master csv
target1b = targets[0] # wgere target1b,target2b are displayed by the two text elements
target2b = targets[1]

thisExp.addData("button1", targets[0])
thisExp.addData("button2", targets[1])