I am new to Python and PsychoPy. Our experiment had been freezing and we could not figure out the issue. It was suggested to us that there was a problem with the ‘while loop’. We were given code to fix that “‘while loop’ freezing issue”. Now, instead of fixing the original problem, this new code comes with a “NameError: global name ‘expData’ is not defined” problem. This had not happened before.
THE CODE:
Lines 62-72:
while not (pReady and oReady):
# Go look for keyboard events
if not pReady:
for key in event.getKeys():
if key in ['left','right']:
pReady = 1
expData[trial]['rt'] = timer.getTime()
if key in ['left']:
expData[trial]['choice'] = 1
else:
expData[trial]['choice'] = 0
# Go look for opponent response
if timer.getTime() > 2.5:
oReady = 1
#??
return [oReady,pReady]
Lines 234-258:
while not (pReady and oReady):
# Go look for keyboard events
if not pReady:
for key in event.getKeys():
if key in ['left','right']:
rt = timer.getTime()
pReady = 1
needDraw = 1
expData[trial]['rt'] = timer.getTime()
if key in ['left']:
expData[trial]['choice'] = 1
else:
expData[trial]['choice'] = 0
THE ERROR:
Traceback (most recent call last):
File "T:\Peipei's TBI data\Data\Pupil-ITI_MS\main.py", line 106, in <module>
PD_trials2.run_trials(tracking, baseName, subNum)
File "T:\Peipei's TBI data\Data\Pupil-ITI_MS\PD_trials2.py", line 602, in run_trials
ret_value = do_trial(tracking, expData, trial, stim, logFile)
File "T:\Peipei's TBI data\Data\Pupil-ITI_MS\PD_trials2.py", line 427, in do_trial
expData[trial]['choice'], expData[trial]['rt'] = drawReady(surf, stim)
File "T:\Peipei's TBI data\Data\Pupil-ITI_MS\PD_trials2.py", line 242, in drawReady
expData[trial]['rt'] = timer.getTime()
NameError: global name 'expData' is not defined
There was no problem with this variable before, is it possible the “timer.getTime()” is creating the error? This is also used earlier on line 68. Is it just not clearing the values to get new ones? Or could it be something else entirely?