Hello, in my flanker task experiment, the first trial has four stimuli, but when I try to save the results to a csv file using saveAsWideText, I only get the first three and these seems to be the same stimulus (in my case the sequence ‘CCCSCCC’) repeated three times.
Here’s the code:
from psychopy import visual, core, data, event, gui
from psychopy.hardware import keyboard
expName = "Eriksen's Flanker Task"
exp = data.ExperimentHandler(name=expName, savePickle=True, saveWideText=True)
kb = keyboard.Keyboard()
trial_timer = core.Clock()
flank_stimuli = ['KKKHKKK','SSSCSSS','HHHKHHH','CCCSCCC'] # experiment stimuli, congruent condition
for stim in flank_stimuli:
if stim[3] == 'H':
correct_response = 'x'
elif stim[3] == 'K':
correct_response = 'x'
else:
correct_response = 'm'
trials = data.TrialHandler(flank_stimuli, 1, method='random')
trials.data.addDataType('RT')
trials.data.addDataType('Response')
trials.data.addDataType('Accuracy')
trials.setExp(exp)
experiment_window = visual.Window(size=(800,600),winType='pyglet',fullscr=True, screen=0,color="black", colorSpace='rgb') # creating the experiment window
experiment_window.mouseVisible = False
screen_text = visual.TextStim(experiment_window,text=None, alignText="center", anchorHoriz='center', color = 'white') # drawing the stimuli
kb.clock.reset()
for trial in trials:
current_time = 0
trial_run = True
trial_timer.reset()
while trial_run:
current_time = trial_timer.getTime()
keys = kb.getKeys(['x', 'm', 'space', 'escape'], waitRelease=True)
if 'escape' in keys:
core.quit()
kb.start()
screen_text.setText('+')
screen_text.draw()
experiment_window.update()
core.wait(1.0)
kb.clock.reset()
screen_text.setText(trial)
screen_text.draw()
experiment_window.update()
core.wait(2.0)
experiment_window.flip()
kb.stop()
for key in keys:
if key == correct_response:
accuracy = 1
else:
accuracy = 0
if not key:
accuracy = 0
RT = key.rt
resp = key.name
exp.addData('Stimulus', stim)
exp.addData('Response', resp)
exp.addData('Accuracy', accuracy)
exp.addData('RT', RT)
exp.nextEntry()
break
trial_timer.reset()
exp.saveAsWideText(fileName='flank_raw_new.csv',appendFile=True)
exp.saveAsPickle(fileName='flank_raw')
experiment_window.close()
core.quit()
Sorry if I made some banal mistake but I’m just a beginner in python