I’m attempting to code an experiment for an animal touch screen task and wanted to have a fixed ratio of 20:1, where the animal is rewarded after successfully touching the presented stimulus in 20 trials. I was attempting to use a while loop with an initialized counter that adds upon mouse press but was having issues with the mouse.getPressed() function because it returns true on any frame during which the mouse is pressed, and therefore my count is not accurately updating.
I’ve managed to write code that successfully updates the count when I want it to but I’m now running into the problem that, if there is no mouse click, the program proceeds directly to the reinforcement block. I wanted to include an elif statement that is contingent upon the mouse not getting pressed, but am not really sure how to do that successfully. I’ve tried a couple things, but always get stuck because getPressed() returns false when the mouse is not pressed and there will always be at least a couple frames where it isn’t pressed but I have no way of knowing what that reaction time will be.
Here’s what I have so far:
# Set up the window win = visual.Window([800,600], fullscr=False, monitor="testMonitor", color = '#ffffff') # make the shape for the left triangle left_triangle = visual.ShapeStim( win=win, name='left_triangle', vertices=[[-(0.5, 0.5)/2.0,-(0.5, 0.5)/2.0], [+(0.5, 0.5)/2.0,-(0.5, 0.5)/2.0], [0,(0.5, 0.5)/2.0]], ori=0, pos=(0, 0), lineWidth=1, lineColor='#f9d70b', fillColor='#f9d70b', opacity=1, depth=0.0, interpolate=True) #make reinforcement cue overlay_1 = visual.ShapeStim( win=win, name='overlay_1', vertices=[[-(0.75, 0.75)/2.0,-(0.75, 0.75)/2.0], [+(0.75, 0.75)/2.0,-(0.75, 0.75)/2.0], [0,(0.75, 0.75)/2.0]], ori=0, pos=(0, 0), lineWidth=1, lineColor='#32df17', fillColor= None, fillColorSpace='rgb', opacity=1, depth=-2.0, interpolate=True) #Mouse mouse = event.Mouse(win=win) left_clock = core.Clock() # left lever presses left_triangle_count = 0 # Initialize a count for the trials old_count = 1 left_clock.reset() while left_clock.getTime() < 5 and left_triangle_count <=20: left_triangle.draw() win.flip() if mouse.getPressed(): left_triangle_count +=1 print left_triangle_count win.flip() core.wait(1.0) ## here's where I lose it! elif not mouse.getPressed(): left_triangle.draw() win.flip() #reinforcement cue left_triangle.draw() overlay_1.draw() win.flip() core.wait(2.0) win.close() core.quit()
Please note that it’s still fairly sparse since I wanted to figure this loop out before working on anything related to output (measuring RT and saving that to a csv file, etc.).
Sorry in advance if this is a bit dense, I am happy to elaborate on anything that is unclear. If anyone can think of a way to do this that doesn’t rely on a counter, that would also be appreciated! I’m just really stuck!