How to randomize texts in a loop

OS Windows 10

PsychoPy version v2023.2.2

What are you trying to achieve?

We have two text box responses set up in our study where participants have to type in the name of a friend, a different name in each text box. We want these names to appear in another routine with our stimuli, and we want these names to be randomized for our participants as they go through this task. Is there a way to randomize the appearance of participant responses from textboxes in a future routine?

If this is not possible, how do you instead put the name responses from the output into a specified excel sheet? We need to change where the names from the output are put for a future step in our study. At the moment, each participant’s two name responses are being deposited into an excel sheet individualized for each participant’s data, and we want to change this output location.

If you put something like name1 and name2 in your spreadsheet, then you could put the following in Begin Routine

if Name == 'name1': # Name is the spreadsheet column name
     thisName = textbox1.text
else:
     thisName = textbox2.text

You will need to put thisName = '' in Begin Experiment

Hi, thank you so much for your response!

We took your advice and implemented it into our program, but we are still having issues. We were able to display “name1” and “name2” from the Excel sheet on the text component for the stimuli routine. We are using the same Excel sheet with the list of 60 emotions. However, it’s showing up as “name1” and not “Jason” (Jason being an example input on the textbox). Is there a way to adjust the code so that “name1” corresponds to the textbox1 response?

We also have the issue of “name1” and “name2” not being randomized in the 120 trials. The first handful of trials do not show any name, then a series of trials are shown as “name1”, and the remaining are shown as “name2”. We need “name1” and “name2” to be fully randomized along with the emotion words for our study. How can we achieve this?

Your help is greatly appreciated! Thank you!

Are you putting $Name in the text component instead of $thisName?

Are name1 and name2 set by the same textbox component or different ones? You could assign the contents to variables in the end of the routine where they are set, e.g. name1 = textbox.text or name[name_loop.thisN] = textbox.text depending on how you are doing it.

We were putting $Name. We just changed it to $thisName. When we ran it, the text component of the stimuli would display the textbox response, however, it wasn’t randomized properly between name1 and name2. It would only show the textbox2 response for the trials and only displayed the textbox1 response twice. We want the names to be randomized, but each name should appear 60 times and should include each of the 60 emotion words only once.

For some reason, it is also displaying the keystroke response after every routine (See attached picture). In the picture, the “5555…” are the keystroke responses. “N” is the name that was written for the textbox2 response. The first trial is also blank with no name.

We are using two different textbox components for name1 and name2. Should we use name1 = textbox.text or name[name_loop.thisN] = textbox.text ?

Thanks again for your help with this!