Free Association Task, show previously generated word

Hi I’m trying to create a free association task in psychopy. I’m pretty novice in terms of the coding and while I’ve been able to get the task itself to work, I would like to show participants the previous word they type in for each subsequent free associate. Given my lack of coding experience, I really am not sure how to go about doing this and would greatly appreciate any help I can get.

In builder, I have a keyboard named key_response, text component with $screen_text in the text

Begin routine:
screen_text = ‘’

Each frame
if(“backspace” in key_response.keys):
key_response.keys.remove(“backspace”)

if(len(key_response.keys) > 0):
    key_response.keys.pop()

elif(“return” in key_response.keys):
key_response.keys.remove(“return”)

if(len(key_response.keys) > 2):
    screen_text = ''.join(key_response.keys)
    thisExp.addData("assn_response", screen_text)

    continueRoutine = False

screen_text = ‘’.join(key_response.keys)

Hi @Aflynn

You can find a nice guide here: Writen response

I just copied the code from that post and matched it to your variable names:

# Begin Experiment
import string
allLetters = list(string.ascii_lowercase)

#Begin Routine Tab
screen_text = ''

# Each Frame Tab
key_response = event.getKeys()
if 'escape' in key_response:
    core.quit()  # So you can quit
else:
    if key_response:
        if key_response[0] == 'backspace':
            screen_text = screen_text[:-1]  # Deletes backspace
        elif key_response[0] in allLetters:
            screen_text+=key_response[0]  # Adds character to text if in alphabet.
        elif key_response[0] == 'return':
            continueRoutine = False

#End Routine
thisExp.addData ("assn_response", screen_text)