Randomize Answers in Psychopy builder/code from Excel sheet

Hello!

I am currently creating an experiment task where I want the participants to view the question and 4 answer choices on the screen at the same time and pick the correct answer. I feel like this should be a simple solution but I have been having a rough time as I want the answer choices randomized on the screen.

I currently have the questions and answer choices all within one excel file; I have a column labeled ‘Questions’, ‘Answers’, ‘Lures’, ‘Choice_3’, and ‘Choice_4’.
I have a loop that is pulling from the appropriate excel file.

I have a routine that loads the excel data prior to the loop.

This is the load_questions routine:


This is my trials loop:

This is my questions_routine routine:

This is my rating routine. The text_1-4 (and the Text_cue) are set up where the box has the appropriate column name (i.e. $Answer):

The code for my rating routine is this:


I feel like there is a way to just pull from the text identifications I give them in the builder (so for example Text_1, rather than $Answer) into a code and do randomization with the positions I define in the code, which is why I used the ‘zip’ feature because thats what I read to use, but I am unsure? Is there a way to do like shuffle() or something else that will pair the Text_1-4 options with a position I defined?

Anything helps! Thanks!

Hello

I think it is sufficient to just shuffle the positions of your text-components and have Answer, Lure, Choice_3 and Choice_3 assigned to their respective text-component.

Begin routine tab

xPos = [-0.17, -0.51, 0.17, -0.51]
shuffle(xPos)
xPosText1 = xPos.pop()
xPosText2 = xPos.pop()
xPosText3 = xPos.pop()
xPosText4 = xPos.pop()

Y-position is always 0. Then in the text-component Text_1 - Layout-tab specify the Position as (xPosText1, 0) set every repeat, in the text-component Text_2 - Layout-tab specify the Position as (xPosText2, 0) set every repeat and so on.

You might want to save the positions.

thisExp.addData("xPosText1", xPosText1)
thisExp.addData("xPosText2", xPosText2)
thisExp.addData("xPosText3", xPosText3)
thisExp.addData("xPosText4", xPosText4)

Place the code-component before the text-components.

By the way, I would choose a name for the text components that reflects their content.

Best wishes Jens

1 Like