TypeError: 'numpy.float32' object is not iterable

Hello,

I am just learning how to code in Python. I downloaded a version of an RDK task with a code component for a staircase method from Gitlab (created by @Becca) for remote research.

I have encountered the following error:

line 1125, in
trials.addData(‘thisStair’, thisStair[‘name’])
File “/Applications/PsychoPy 4.app/Contents/Resources/lib/python3.8/psychopy/data/trial.py”, line 731, in addData
self.data.add(thisType, value, position=None)
File “/Applications/PsychoPy 4.app/Contents/Resources/lib/python3.8/psychopy/data/base.py”, line 532, in add
repN = sum(self[‘ran’][self.trials.thisIndex])
TypeError: ‘numpy.float32’ object is not iterable
################ Experiment ended with exit code 1 [pid:28613] #################
324.1558 DEBUG DlgLoop: could not determine if a condition filename was edited

The trial routine begins with a text component and a dot video. Once I make a response (press either the left or the right key), the task crashes. No more trials run after that.

I think the error in the code can be found in the “end routine” section of my code component.

save information to output file
trials.addData(‘thisStair’, thisStair[‘name’])
trials.addData(‘this_level’, thisStair[‘this_level’])
trials.addData(‘Response’, key_resp.keys)
trials.addData(‘currentDirection’, thisStair[‘currentDirection’])
trials.addData(‘corrAns’, corrAns)
trials.addData(‘currentStepSize’, thisStair[‘thisStep’])

check if correct, adjust orientation and add to reversal vals (if needed)

if key_resp.corr:
print(‘Answer correct!’)
trials.addData(‘corr’, 1)
if thisStair[‘currentDirection’] == ‘down’:
if thisStair[‘this_level’] > thisStair[‘minVal’]:
thisStair[‘this_level’] -=thisStair[‘stepSize’]
else:
print(‘minimal value reached maintaining current val’)
else:
thisStair[‘currentDirection’] = ‘down’
thisStair[‘reversalVals’].append(thisStair[‘this_level’])
if thisStair[‘stepSize’] != thisStair[‘stepSizes’][-1]:#if this is not the minimal stepsize
thisStair[‘thisStep’] +=1
else:
trials.addData(‘corr’, 0)
if thisStair[‘currentDirection’] == ‘down’:
thisStair[‘currentDirection’] = ‘up’
thisStair[‘reversalVals’].append(thisStair[‘this_level’])
if thisStair[‘stepSize’] != thisStair[‘stepSizes’][-1]:#if this is not the minimal stepsize
thisStair[‘thisStep’] +=1
if thisStair[‘this_level’] < thisStair[‘maxVal’]:
thisStair[‘this_level’] += thisStair[‘stepSize’]
else:
print(‘max value reached. keeping current value’)

if thisStair has reached max reversals or nTrials

remove it from the list of stairs

if len(thisStair[‘reversalVals’]) == thisStair[‘nReversals’]:
completedStairs.append(thisStair)
stairs.pop()
print(‘nReversals reached, ending this staircase’)
elif thisStair[‘trialCount’] == thisStair[‘nTrials’]:
completedStairs.append(thisStair)
stairs.pop()
print(‘nTrials reached, ending this staircase’)

if len(stairs)==0:
print(‘stairs completed, ending now’)
continueRoutine = False
trials.finished=True

I am using v2022.1.1 of PsychoPy, macOS Catalina (v10.15.7)
Thank you in advance for your help!

Victoria