OS: Windows 8.1
PsychoPy version: 1.85.6
Basically, I have 3 different tasks I want the participants to respond. These tasks need to be randomized for each participant and include a practice example and a message saying the task will begin before the actual task starts.
For the task randomization I tried to use a loop including all the routines, but taking into account that I have more than 1 condition file this wasn’t possible.
For the practice example and the message indicating the task will start I tried to include a routine before the actual routine tasks, but considering these are inside a loop (with the purpose of randomizing the task stimuli), the message repeats after every response. One solution I thought was to create a routine before each task loops, but as my objective is randomize all the tasks, this didn’t seem a good approach because maybe the software would randomize the practice examples and messages with all the other task routines and would not begin in the order “practice → star message → actual task”.
This is the experiment file
experimentoJMA.psyexp (65.2 KB)
Therefore, what I need is to put the “practice example” and “begin task message” before the Dilemmas and RMET routines (see file) and randomize all the tasks in the bigger loop.
Any suggestions?
Hi @Bruno_Dalpiaz, if I understand your requirements correctly, you can insert a routine with a code component that only displays text on the first iteration of your most outer loop i.e., Tarefas_loop
. So, create a new routine with a code component, a text component (called “myText”) and a keyboard component (for ending the routine) called “introText” (as an example) and add the following to the code component under “Start Routine” tab:
if Tarefas_loop.thisN == 0:
myText.setText("This is the task demo text")
myText.setAutoDraw(True)
win.flip()
elif Tarefas_loop.thisN > 0:
continueRoutine = False
Then add the following to the “End Routine” tab:
if Tarefas_loop.thisN == 0:
myText.setAutoDraw(False)
win.flip()
You will then need to insert the new routine into the flow just before your looping routines e.g., Dilemas_A_routine
but within your outer Tarefas_loop
1 Like
Hey @dvbridges, the text before the tasks is working great. Now the intro for each routine isn’t reapeating after every response.
Still, my last doubt regards the randomization of the routines I’ll use (Dilemas_A_Routine, EMRI and oRMET). I tried to set an unified conditions file in the Tarefas_loop but it just repeats several conditions with no need. Also, it begins with the Dilemas_A_Routine every time I execute the experiment. Any suggestion ?
Thank you very much for your help.
@Bruno_Dalpiaz, great. I think I have a solution to your randomization problem. @Michael shows how to randomize routine order in this response here.
Routine randomization
You need to include another conditions file in your Tarefas_loop
which conditionally presents a routine using binary indicators - see attached nnReps.xlsx sheet. The columns in the sheet are nReps1:nReps3 and a 1 indicates to present a routine and 0 indicates to not present a routine. So, you go to your routine loop of interest e.g., Dilemas_A_loop, and in the field nReps
you enter nReps1 as a variable. Do the same for your other routines e.g., for EMRI, enter nReps2 in the nReps
field. This controls the randomization of your routines (so long as “Random” is selected in the Tarefas_loop
.
Introductory text on each routine for first iteration only
To ensure instructions appear on your first iteration of the experiment only, see the code component in the attached Builder file - we will use EMRI as an example. In the code component, you need to initiate a counter at the beginning of the experiment:
cancelEmriText = 0
Then, add the following at the beginning of a routine, to ensure the text is only written on the first iteration:
if Tarefas_loop.thisN <= 2 and not cancelEmriText > 0:
cancelEmriText = cancelEmriText + nReps2 # nReps2 because see EMRI loop handler
emriText.setText("Intro to EMRI")
emriText.setAutoDraw(True)
win.flip()
else:
continueRoutine = False
pass
Then, at the end of the routine, turn off autodraw:
if cancelEmriText > 0:
emriText.setAutoDraw(False)
win.flip()
Repeat for all your routines - but see attached example. You will have to flatten your data for each participant, as you will have several rows for each trial, but that is easily processed. There may be a better way to store the data.
experimentoJMA_example.psyexp (56.6 KB)
nnReps.xlsx (8.6 KB)
thank you so much @dvbridges, the experiment is running great and this was really helpul!
Best Regards
hey @dvbridges, although the randomization is working, when I use characters like “ç” and “ã” in this part of the code component: emriText.setText("Intro to EMRI")
, the experiment crashes instantly. Do you have any solution for this problem?
Thank you very much
Hi @Bruno_Dalpiaz, I am guessing your error relates to the encoding, but I will need to see the error. You could try and prefix your string with a u to create a unicode representation of your text e.g., u"Intro to EMRI"
but if that doesnt work please paste your error output.
1 Like
Thanks @Bruno_Dalpiaz , did you try the u"" prefix? You received the UnicodeDecodeError
because the string you have supplied is a byte-string in Python 2, which only allows the representation of 256 characters, which is fine if you are using only ASCII characters. Unicode will provide the representation of character sets with accented characters. See also python docs for Unicode
I can replicate your error using Spanish characters in the setText method, but prefixing the string with a u e.g., u"This works for ç"
fixes the error.
hey @dvbridges, I was trying to put the u before the parenthesis, that why it wasn’t working, now I corrected the problem and I can use the characters I needed. Thank you very much.
1 Like