Use text input as stimulus in following trials

I’m trying to create a text-based experiment in which participants are shown 1 word and told to respond by writing in 3 more words. In the following trial, the participant is shown the first of their previously written items, i.e., if they wrote ‘cat’, ‘dog’, ‘bird’, then in the 2nd trial they are shown ‘cat’ and asked to write in 3 more words. To do this I need to save the participants responses during the task, and not just in the end routine when it is written to the csv output file. Is it possible to save the responses to a text file and then access that text file for the stimuli in a later trial? Or, save the responses as a variable to later access them?


Does the textinput script have a code component in Each Frame / End Routine? I would expect that the input is already being saved to a variable.

The command that saves something to the csv file is thisExp.addData(‘Column name in CSV’,variableNameInPsychoPy)

Best wishes,


Hi Wakefield - I understand that the input is being saved - but its being saved to the csv file at End Routine. That’s not helpful if I want to access that saved input DURING the experiment. At least I haven’t figured a way that it could be helpful.
As to the issue of what is already in the script - I should’ve mentioned that there is no code component. I used a loop in the Builder so as to make the first trial. I need help with the code on saving and then accessing the input in the following trials.

Is this a code component?

If so, what is the End Routine code?

Since my first entry I’ve learned I can make a variable and then access that variable to use as stimuli in a later trial. Using the code component from textinput, I have this as Begin Routine, wherein response is the variable meant to store the responses.

response = []
modify = False
text.text = ‘’

This came with the textinput code component for Each Frame:

keys = event.getKeys()
if len(keys):
if ‘space’ in keys:
text.text = text.text + ’ ’
elif ‘backspace’ in keys:
text.text = text.text[:-1]
elif ‘lshift’ in keys or ‘rshift’ in keys:
modify = True
elif ‘return’ in keys:
continueRoutine = False
if modify:
text.text = text.text + keys[0].upper()
modify = False
text.text = text.text + keys[0]

And in End Routine I added one line for the response variable

thisExp.addData(“typedWord”, text.text)
response = response.append(“typedWord”)

I don’t understand the use of “typedWord” in the addData function seeing as it is no where in the documentation and likely doesn’t work in this script seeing as the program crashes at this stage and does not go on to the next trial

The next trial is where I want to use the text input written by the participant in trial 1. In the stim presentation block in the builder, named targetText2, I added a code component with this:

targetText2 = response[1]

typedWord is the name of the data column in Excel. Before it gets written to Excel it is a key in a “dictionary”. The code means save the individual word to the data file and then the next line means add the word you just saved to the overall response (an array of words).

Thanks for the clarification on “typedWord”.
With the above code, the program crashes before trial 2 starts. Any idea why?
Either this line,
response = response.append(“typedWord”)
is interfering, or its a problem of the next trial.
I’m guessing that this line from trial 2,
targetText2 = response[1]
is the problem. I’ve tried some other options but to no avail. I haven’t been able to get a word from the variable, response, to show as the stimuli in trial 2.

This is asking for the second item in the array which will only work if len(response) > 1. You could try response[0]

Actually I think that it should just be response.append(text.text). “typedWord” in quotes will give typedWord, not the word that was typed. You also need response= in Begin Experiment (or at least before you append to it but not so close that it keeps resetting every word) so that it’s defined.

Thanks again - silly mistake with the “typedWord” issue. I put the response=[] prior to the first loop, and changed the append code to just, response.append(text.text). Now trial 2 starts with the stimuli taken from response[], as I wanted.
Thanks a lot for your patience!

hi all,
I think I have a similar problem.
I am trying to modify a textbox input and return the result on the display in the next routine.
I am using builder and I want to run the experiment online.
In the code component, begin experiment:


end routine:


-which gets translated-


when I try to display response in a text component in the next routine, it works when I put $response in the text field. However, I cannot modify it (I want to multiply the value). If I try to index with $response[0] and run it in pavlovia, a strange “Hello world” gets displayed.

Thank you in advance for your time.