I’m very new to PsychoPy and and Python in general, I’m pretty much learning as I go along.
I’m using PsychoPy Coder to design a simple task.
The task involves the participant playing a game with two other players, controlled by the computer. The participant selects which computer player they wish to ‘pass’ an imaginary ball to, by pressing A or B respectively. The computer player they pass to then randomly either passes to the other computer player, or back to the participant. These ‘ball passes’ are just displayed as text stimuli, informing where the ball has been passed.
I’ve written the following code to do this (again, apologies if it is messy or there is some obvious mistake, I’m very inexperienced):
#participant makes their decision to pass to either computer player A or player B (text stimuli are defined earlier in code not shown) text_dplayer.draw() mywin.flip() allKeys=event.waitKeys(keyList=['a','b']) #recognising participant choice, then setting a variable 'decision' to 'a' or 'b' to remember participant choice for thisKey in allKeys: if thisKey=='a': text_7.draw() mywin.flip() core.wait(5) text_2.draw() mywin.flip() decision = 'a' core.wait(5) elif thisKey=='b': text_8.draw() mywin.flip() core.wait(5) text_2.draw() mywin.flip() decision = 'b' core.wait(5) #list of possible options for computer player A (text stimuli describes either passing to player B or passing back to the participant) pickB = text_9.draw() pickPa = text_10.draw() actionsA = [ pickB, pickPa, ] #list of possible options for computer player B (text stimuli describes either passing to player A or passing back to the participant) pickA = text_11.draw() pickPb = text_12.draw() actionsB = [ pickA, pickPb, ] #list is referenced and random choice is made by computer if decision=='a': random.choice(actionsA) mywin.flip() core.wait(5) elif decision=='b': random.choice(actionsB) mywin.flip() core.wait(5)
The issue is, instead of randomly displaying a single possible text stimuli from the list actionsA or actionsB (depending on whether the participant passes to A or B), all text stimuli from both lists are all displayed together in the PsychoPy window (e.g., instead of just showing “Player A passed the ball back to you!”, it shows all four possible text stimuli overlaid).
I have re-created this code just using basic Python code, no PsychoPy stuff (i.e. printing text instead of creating text stimuli) and it works as I want it to. But I can’t figure out why it doesn’t work this way in PsychoPy.
Thank you very much in advance for any help you can offer.
University of Nottingham