Independent Randomization in Builder

OS (e.g. Win10):

PsychoPy version (2023.1.3):

What are you trying to achieve?:

I’m trying to build an experiment that contains 90 images of two types (60 Negative and 30 Neutral) and two types of instructions: “View” (i want it to be displayed 60 times) or “Reappraise” (i want it to be displayed 30 times). The participants will see one image for 1 second, then an instruction will appear in front of the image and disappear after 2 seconds, so that the image continues for more 6 seconds, like this:

This will happen 90 times, and every repeat will choose a different image and one of the two instructions, until all the images are shown once. I want the two variables “Image” and “Instruction” to be independently randomized. For example, image_34 can be matched with “View” for the first participant, but for another participant, it will be matched with “Reappraise”, and so on.

What did you try to make it work?:

I created an excel file with both variables (I used “View” 60 times and “Reappraise” 30 times):

And set the loop to random and referred the image componente to the column “Image” of the excel file:

I added a text component and set the text to be $Instruction (second column of the excel file):

What specifically went wrong when you tried that?:
The variables are tied to each other. Randomization chooses one row, and displays the image and instruction of the same row. I want the two variables to be independently randomized (for each participant), for example: shows image from row 2, but instruction from row 30.

I know there is a demo of independent randomization. And i know the variables should be in different files. However, i don’t know how to do it, since i want both variables to be displayed in the same routine. I also know that there is a way to simultanously run two routines. However, i’m new to both Psychopy and programming in general, so i’m not understanding much…

My independent randomisation demo preloads one column from the spreadsheet into a list and then during the trials loop uses values from that list instead of from the spreadsheet.

I deleted the instruction column and had put it now as a list in a code component.

In the “begin experiment tab”, i added this:

Instrucao_texto = ([‘Visualizar’] * 60) + ([‘Reavaliar’] * 30)
shuffle(Instrucao_texto)

And in the “begin routine tab” i added this:

text = Instrucao_texto.pop()
thisExp.addData(text, text)

I also added a text component, and in the text box i had put this “$Instrucao_texto”.

But when i try to run, this error appears:
AttributeError: ‘str’ object has no attribute ‘tStart’

text = Instrucao_texto.pop()

text is the name of your text component

You can either set the text displayed in a text component called text by setting the text component itself to display nothing / constant and then use
text.text = Instrucao_texto.pop()

Alternatively set it to display $msg / each repeat (or each frame if the value is going to change in Each Frame code) and then use

msg = Instrucao_texto.pop()

msg could be a different variable name, but not Instrucao_texto which is a list.

I used this alternative and now it doesn’t show any error:

“Alternatively set it to display $msg / each repeat (or each frame if the value is going to change in Each Frame code) and then use ‘msg = Instrucao_texto.pop()’”.

However, regarding the manual data save, would be “thisExp.addData(msg, msg)”?

How about

thisExp.addData('Instrucao_texto', msg)

Thank you very much! It seems to be working correctly!

1 Like