Dissertation code help!

so i am trying to create an experiment that shows participants a list of words then asks them to recall the words. i got it to work up to input section where it crashes can anyone help please?!!

import psychopy.visual
import psychopy.event
import psychopy.core
import random
import csv

win = psychopy.visual.Window(size=(800, 600), fullscr=False)

intro_text = "Welcome to the experiment! try to remember as many words as possibl. Press any key to start the experiment."
intro_stim = psychopy.visual.TextStim(win=win, text=intro_text)
intro_stim.draw()
win.flip()
psychopy.event.waitKeys()

blank_stim = psychopy.visual.Rect(win=win, width=800, height=600, color='grey')
blank_stim.draw()
win.flip()
psychopy.core.wait(1)

focal_point_stim = psychopy.visual.Circle(win=win, radius=50, color='black')
focal_point_stim.draw()
win.flip()

words = ['Family', 'mums', 'beat', 'shout', 'anger', 'marriage', 'divorce', 'dads', 'trauma', 'care', 'Dogs', 'happy', 'sad', 'red', 'Instagram', 'fashion', 'music', 'architecture', 'trains', 'party']
random.shuffle(words)

for word in words:
    word_stim = psychopy.visual.TextStim(win=win, text=word)
    word_stim.draw()
    win.flip()
    psychopy.core.wait(1)


blank_stim.draw()
win.flip()
psychopy.core.wait(1)

response_text = "Please enter the words you remember, separated by a comma: "
response_stim = psychopy.visual.TextStim(win=win, text=response_text)
response_stim.draw()
win.flip()

text_box = psychopy.visual.TextBox(win=win, text="", font_size=24, font_color='black')
text_box.draw()
win.flip()

response = text_box.get(closeOnText=False, leaveOnOverflow=True, acceptText=False)

with open('memory_data.csv', 'a') as csvfile:
    writer = csv.writer(csvfile)
    writer.writerow([response])

win.close()

Hi MRBZ, I actually think what you are trying to achieve would be very easy to do in builder. So I highly recommend you shift this study over into builder.

In builder, you would just need to move your words variable to a code component. You could then use random.shuffle(words) in a begin routine tab (if you need it randomsied on every loop iteration), or in the begin experiment tab, if you only need it randomised once for each participant.

thank you so much, is there an easy way of transferring code to builder or a video that explains how to make this kind of study in builder?

Hello,

it is a one-way street from builder to code but not the other way around. Parts of code might be reused in code-components. An excellent source is:
Peirce, J. W., Hirst, R. J. & MacAskill, M. R. (2022). Building Experiments in PsychoPy. 2nd Edn London: Sage.

Best wishes Jens

PsychoPy’s you tube channel, Jason Ozubko’s you tube channel…both excellent resources for getting started with Builder.