The code I'm writing puts up a shape on screen and allows for manipulation of the shape via the up/down arrow keys. What I've been trying to get it to do is make the amount the shape changes dependent on the sequence of keypresses; as long as the input is the same as the initial keypress, the amount the shape changes will be large. However, when the first 'reversal' of key press occurs (for instance, to make fine adjustments), every key press after that point (regardless if it is the same as the initial button press) should change the circle by a much smaller proportion (not interatively, just 0.1cm change rather than 2cm). The code has been written in Psychopy.
I think I've not grasped the way the loops should be set out for this, but I can't see how they might be changed to do what I want. Apologies for the actual code as opposed to a minimal example - any advice is much appreciated.
for thisTrial in trials:
endKey = 0
nKeypress = 0
count = 0
counting = 0
if thisTrial == 'ellipse':
ellipseHeightinit = 7.6,1.9 + (round(numpy.random.uniform(-1,1),1))
elif thisTrial == 'circle':
ellipseHeightinit = 7.6,7.6 + (round(numpy.random.uniform(-1,1),1))
ellipseHeight = ellipseHeightinit
ellipseStim.setSize(ellipseHeight, log = False) # set the initial size of the shape
while endKey == 0:
ellipseStim.setAutoDraw(True)
win.flip() # flip the window to see the stimuli
allKeys = event.waitKeys()
if count < 1: #store the first keypress made
for thisKey in allKeys:
firstKeypress = thisKey
count += 1
event.clearEvents()
for thisKey in allKeys: # change the size of the shape depending on key pressed
if thisKey == 'up':
nKeypress = nKeypress + 1
elif thisKey == 'down':
nKeypress = nKeypress - 1
elif thisKey == 'space':
endKey = 1
while counting < 1: # attempt to make step size large until reversal
if thisKey == firstKeypress:
ellipseHeight = 7.6, ellipseHeightinit[1] + nKeypress*20
break
elif thisKey != firstKeypress:
ellipseHeight = 7.6, ellipseHeightinit[1] + nKeypress*0.1
counting += 1
break
ellipseStim.setSize(ellipseHeight, log = False) # set new shape size
ellipseStim.setAutoDraw(False)
for instance, to make fine adjustments)?whileloop, neitherthisKeynorfirstKeypressis changed. So, either you're going to hit theifand break out the first time, or hit theelifand break out the first time, or spin forever doing nothing and never leave the loop.