Hi all,
I’m trying to create a script that will have the participant redo trials that they got incorrect. Essentially, the participant is first shown pictures in a specific location on the screen. Later, they must drag and drop the image in the correct location (coordinates cx,cy). If they get a trial wrong they’re shown the correct position, a sound is played and they have to repeat it, if they get it right then they don’t. they keep repeating trials they got incorrect until they were all right. Below is my code, I know it’s a bit messy.
TestIteration = 0
TestIteration += 1
# Set the excel sheet to use for this trial
TestExcelSheet = TestPhaseFilename + str(TestIteration).zfill(2) + '.csv'
# set up handler to look after randomisation of conditions etc
TestingPhase = data.TrialHandler(nReps=1, method='random',
extraInfo=expInfo, originPath=-1,
trialList=data.importConditions(IncorrectAnswers),
seed=None, name='TestingPhase')
thisExp.addLoop(TestingPhase) # add the loop to the experiment
myMouse.setVisible(1)
WrongAnswers = []
IncorrectAnswers = []
CorrectMsg = visual.TextStim(win = win, units = 'norm', height = 0.1,
pos = (0,0), text = "Correct!", alignHoriz = 'center',
alignVert = 'center', color = [0, 0, 0], wrapWidth=1)
ImagesToRedo = 0
for testImgii in TestingPhase:
currentLoop = testImgii
# Set some basics
t = 0
globalClock.reset() # clock
if testImgii != None:
for paramName in testImgii:
exec('{} = testImgii[paramName]'.format(paramName))
ContinueStim = True
# Set the objects for this trial
DragImage.setImage(ImageN)
bingoCircle.setPos((cx,cy))
DragImage.setPos(0,0)
CompoundSound = sound.Sound(SoundID)
myMouse.setPos(0,0)
# Instead of ContinueStim, can use nextEntry()
while ContinueStim:
# Draw the object to screen
if bingoCircle.status == NOT_STARTED:
bingoCircle.setAutoDraw(True)
if DragImage.status == NOT_STARTED:
DragImage.setAutoDraw(True)
# Drag and drop image using mouse
if DragImage.contain(myMouse) and myMouse.getPressed(0):
DragImage.pos = myMouse.getPos()
# When the mouse is released
if not myMouse.getPressed(0):
finalAnswer = myMouse.getPos()
if bingoCircle.contains(DragImage):
# Correct answer!!
CorrectMsg.setAutoDraw()
ContinueStim = False
else:
# Incorrect answer produces correct position and sound
DragImage.setPos((cx,cy))
CompoundSound.play()
ContinueStim = False
# Get the stimuli parameters and write to new excel file
WrongAnswers.append( TestingPhase._getLoopInfo(currentLoop) )
IncorrectAnswers.append({'ImageN' : ImageN, 'SoundID' : SoundID, 'cx' : cx, 'cy' : cy})
ImagesToRedo += 1
# When this trial is done, record it
if not ContinueStim:
# Perhaps use event.xydist() to measure distances
TestingPhase.addData('ImgTimeSpent', t)
TestingPhase.addData('PositionAnswer', finalAnswer)
# For the output below, set the distance to cm
TestingPhase.addData('DistanceFromBingo', myMouse.mouseMoved(distance=True))
TestingPhase.addData('TimeImgPressed', myMouse.mouseMoveTime())
TestingPhase.addData('ImageWrong', DragImage)
# Stop loop if 'esc' key is pressed
if event.getKeys(keyList=["escape"]):
core.quit()
win.flip()
routineTimer.reset()
win.flip()
if bool(ImagesToRedo):
NextMsg = 'There are still ', ImagesToRedo, ' images to correctly place'
else
NextMsg = 'Congragulations! You got them all right! You''re done! Left-Click to exit'
I’m also trying to store time spent on each trial and number of times it to get an individual trial correct. I know this is a lot. Any help would be greatly appreciated.
Thank you and have a good day,
Noah