| Reference | Downloads | Github

How to store randomized positions of text stimuli

Hello, I’m using PsychoPy Builder mode to build an experiment where the participants watch a video and answer a question with 3 different answers. Which looks like this;

and the participants respond via “left”, “right” or “down” key presses depending on the position of the right answer (left keypress for the top answer, down keypress for the middle answer and right keypress for the bottom answer).

So, I wanted to randomize the order of the questions for each participant and used this code component;

and I put positions.pop() command as the position for each question stimuli. As indicated in this topic; Randomization of columns in condition file

However, I had a similar issue with storing the positions of the stimuli and get the; ‘Choice’ is not defined error. As I understood, in the recommended solution, the key component is a part of the code, however, I just need to know if the participant selected the right answer (which is always answer1 in my case but I do not know in which position answer1 appeared. So my question is, how can I store in which position the “answer1” text component appeared on the screen or is there a way to know if the selected answer was “answer1”, regardless of the position?


I solved this problem in my experiment and I think you can use the same strategy. However, I am not sure if it is the best one or not.

#On the End Routine tab:

if text1.pos [1] == 0.4 and Choice.keys [0]== 'left': chose= 'top'
if text1.pos [1] == 0 and Choice.keys [0]== 'down': chose= 'top'
if text1.pos [1] == -0.4 and Choice.keys [0]== 'right': chose= 'top'
if text2.pos [1] == 0.4 and Choice.keys [0]== 'left': chose= 'middle'
if text2.pos [1] == 0 and Choice.keys [0]== 'down': chose= 'middle'
if text2.pos [1] == -0.4 and Choice.keys [0]== 'right': chose= 'middle'
if text3.pos [1] == 0.4 and Choice.keys [0]== 'left': chose= 'down'
if text3.pos [1] == 0 and Choice.keys [0]== 'down': chose= 'down'
if text3.pos [1] == -0.4 and Choice.keys [0]== 'right': chose= 'down'

# Add the variable chose to my data file for each trial 
thisExp.addData('chosenOne', chose)

You can play around the code and pick more relevant variable names and I hope it could solve your problem.

Hello, thank you for your answer! The problem was solved after we added this code to the end routine section; exptrial.addData(“rightanswerpos”, answer1.pos[1]) and it gave us the position of answer1 in the data file.

1 Like

That is great. Happy it works.