so far this is what my code looks like. I know the answer lies somewhere in the if mouse.getspressedin function I’m just not sure where to insert it in my code.
trialClock = core.Clock()
polygon = visual.Rect(
win=win, name='polygon',
width=(1.5, 1.5)[0], height=(1.5, 1.5)[1],
ori=0, pos=(0, 0),
lineWidth=1, lineColor=1.0, lineColorSpace='rgb',
fillColor=1.0, fillColorSpace='rgb',
opacity=1, depth=0.0, interpolate=True)
targetstimulus = visual.Polygon(
win=win, name='targetstimulus',units='deg',
edges=487, size=(0.4, 0.4),
ori=0, pos=(0, -.70),
lineWidth=1, lineColor=u'white', lineColorSpace='rgb',
fillColor=u'white', fillColorSpace='rgb',
opacity=1, depth=-1.0, interpolate=True)
FOODRESPONSE = visual.TextStim(win=win, name='FOODRESPONSE',
text=u'YAY FOOD',
font=u'Arial',
pos=(0, 0), height=0.1, wrapWidth=None, ori=0,
color=u'white', colorSpace='rgb', opacity=1,
depth=-2.0);
mouse1 = event.Mouse(win=win)
x, y = [None, None]
# Create some handy timers
globalClock = core.Clock() # to track the time since experiment started
routineTimer = core.CountdownTimer() # to track time remaining of each (non-slip) routine
# ------Prepare to start Routine "trial"-------
t = 0
trialClock.reset() # clock
frameN = -1
continueRoutine = True
routineTimer.add(10.000000)
# update component parameters for each repeat
polygon.setFillColor(u'red')
polygon.setLineColor(u'red')
# setup some python lists for storing info about the mouse1
# keep track of which components have finished
trialComponents = [polygon, targetstimulus, FOODRESPONSE, mouse1]
for thisComponent in trialComponents:
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# -------Start Routine "trial"-------
while continueRoutine and routineTimer.getTime() > 0:
# get current time
t = trialClock.getTime()
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *polygon* updates
if t >= 0.0 and polygon.status == NOT_STARTED:
# keep track of start time/frame for later
polygon.tStart = t
polygon.frameNStart = frameN # exact frame index
polygon.setAutoDraw(True)
frameRemains = 0.0 + 9- win.monitorFramePeriod * 0.75 # most of one frame period left
if polygon.status == STARTED and t >= frameRemains:
polygon.setAutoDraw(False)
# *targetstimulus* updates
if t >= 0.0 and targetstimulus.status == NOT_STARTED:
# keep track of start time/frame for later
targetstimulus.tStart = t
targetstimulus.frameNStart = frameN # exact frame index
targetstimulus.setAutoDraw(True)
frameRemains = 0.0 + 9- win.monitorFramePeriod * 0.75 # most of one frame period left
if targetstimulus.status == STARTED and t >= frameRemains:
targetstimulus.setAutoDraw(False)
# *FOODRESPONSE* updates
if t >= 0.0 and FOODRESPONSE == NOT_STARTED:
# keep track of start time/frame for later
FOODRESPONSE.tStart = if mouse1.isPresssedIn(targetstimulus)
FOODRESPONSE.frameNStart = frameN # exact frame index
FOODRESPONSE.setAutoDraw(True)
frameRemains = 0.0 + 2- win.monitorFramePeriod * 0.75 # most of one frame period left
if FOODRESPONSE.status == STARTED and t >= frameRemains:
FOODRESPONSE.setAutoDraw(False)
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in trialComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# check for quit (the Esc key)
if endExpNow or event.getKeys(keyList=["escape"]):
core.quit()
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
# -------Ending Routine "trial"-------
for thisComponent in trialComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# store data for thisExp (ExperimentHandler)
x, y = mouse1.getPos()
buttons = mouse1.getPressed()
thisExp.addData('mouse1.x', x)
thisExp.addData('mouse1.y', y)
thisExp.addData('mouse1.leftButton', buttons[0])
thisExp.addData('mouse1.midButton', buttons[1])
thisExp.addData('mouse1.rightButton', buttons[2])
thisExp.nextEntry()```