Hello, I’m coding my experiment in pycharm.
The event.clearEvents() is not working for me. The right/left keys are still stored and used in the next stimuli presented.
I also have another event.clearEvents() during the fixation stimuli and but it did not help.
I’m attaching my code. am I missing something?
thank you very much
def runningSlotMachines(block, win, info, blockNum, feedback, timer, kb, t, part, WL_variables, group, training):
money = 0
timer.reset()
# event.clearEvents()
while timer.getTime() < 3: # 3 seconds for a response
event.clearEvents()
presentTime = dataClock.getTime() # save the current time the decision was made for later to write in csv
# (you can't put it here because reward value is defined only later
trial_start = dataClock.getTime()
slotMachineImage(win, block[part][t][1], 0.5) # right image
slotMachineImage(win, block[part][t][0], -0.55) # left image
win.flip()
keys = kb.getKeys(keyList=['left', 'right'])
if timer.getTime() > 3:
# x = visual.TextStim(win=win, text='Too slow - you lost ${}'.format(WL_variables["tooSlow"]), color="black",
# bold=True) # english
x = visual.TextStim(win=win, text='איטי מידי! הפסדת {} שקלים '.format(WL_variables["tooSlow"]), color="black",
bold=True, languageStyle='RTL', units='norm')
x.draw()
win.flip()
core.wait(5)
timer.reset()
reward = float("NAN")
response = 'TooSlow'
money -= WL_variables["tooSlow"] # because it is 0.75 and not -0.75
trial_end = float('nan')
rt = float('nan')
datawriter.writerow([presentTime, info['SubjectID'], info['Dominant hand'], group, blockNum,
part, block[part][t][0], block[part][t][1], response, reward, '', '', '', '', '', '',
trial_start, trial_end,
rt,'', '', ''])
# event.clearEvents() # ensures that you only respond to a key that was actually pressed after the onset of the target,
# and discard any that may have been pressed during the image display time
continue
if 'left' in keys:
trial_end = dataClock.getTime()
rt = trial_end - trial_start
response = block[part][t][0]
position_image = -0.55
reward, money1 = winningProbabilitiesMachines(settings, part, response, feedback, win, position_image,
timer, WL_variables, training, t)
money += money1
datawriter.writerow([presentTime, info['SubjectID'], info['Dominant hand'], group, blockNum,
part, block[part][t][0], block[part][t][1], response, reward, '', '', '', '', '', '',
trial_start, trial_end,
rt, '','', ''])
if feedback == 0:
win.flip()
randomWait(win, 1)
break
elif 'right' in keys:
trial_end = dataClock.getTime()
rt = trial_end - trial_start
response = block[part][t][1]
position_image = 0.5
reward, money1 = winningProbabilitiesMachines(settings, part, response, feedback, win, position_image,
timer, WL_variables, training, t)
money += money1
datawriter.writerow([presentTime, info['SubjectID'], info['Dominant hand'], group, blockNum,
part, block[part][t][0], block[part][t][1], response, reward, '', '', '', '', '', '',
trial_start, trial_end,
rt,'', '', ''])
if feedback == 0:
win.flip()
randomWait(win, 1)
break
event.clearEvents()
return money