OS (e.g. Win10): Win10 PsychoPy version (e.g. 1.84.x): v1.90.2 and also PsychoPy 2020.1.3 Standard Standalone? (y/n) If not then what?: Yes What are you trying to achieve?:
I am trying to set the position of the responses typed with the keyboard at pre-determined positions. Here is the task: Observers are presented with a stimulus for 10 seconds, they need to press a key whenever they detect a change in the stimulus. When the trial is finished, these key presses are shown as white bars on a long line representing the duration of the trial (see below).
What did you try to make it work?: Here is what I did to set the position of the written response:
for position in positions: # 'positions' is the list of positions for written response
writtenText.pos = (position ,50)
writtenText.text = "".join(response.keys) #'response.keys' is the keys they press (2, 3, 4 ...)
writtenText.draw()
for i in range(response.keys): # 'positions' is the list of positions for written response
writtenText.pos = (position[i] ,50)
writtenText.text = "%s"%(response.keys[i]) #'response.keys' is the keys they press (2, 3, 4 ...)
writtenText.draw()
Here you set the position AND text on each iteration of the for loop. In your previous example there you iterate through a list of positions and set the position on each iteration, but the text is the same on each iteration (which is why you can joined “234” at each position )
Here, I think there is a typo: writtenText.pos = (position[i] ,50)
So I changed it as: writtenText.pos = (positions[i] ,50)
Then, I run the code, but this error occurred:
for i in range(response.keys): # ‘positions’ is the list of positions for written response
TypeError: ‘list’ object cannot be interpreted as an integer
So I removed range():
for i in response.keys: # 'positions' is the list of positions for written response
writtenText.pos = (positions[i] ,50)
writtenText.text = "%s"%(response.keys[i]) #'response.keys' is the keys they press (2, 3, 4 ...)
writtenText.draw()
But now this error occurred:
writtenText.pos = (positions[i] ,50)
TypeError: list indices must be integers or slices, not str
I would really appreciate if you can tell me what is wrong!
for i in range(len(response.keys)): # 'positions' is the list of positions for written response
writtenText.pos = (positions[i] ,50)
writtenText.text = "%s"%(response.keys[i]) #'response.keys' is the keys they press (2, 3, 4 ...)
writtenText.draw()