OS: Win10 PsychoPy version: 3.0.2 Standard Standalone?: Y, I think so What are you trying to achieve?: To have one of three images appear depending on button press (left, right, down)
Disclaimer: Super amateur level programmer. Only worked with pascal and c++ at an entry level previously so my understanding of python is extremely limited. Talk to me as if I were the village idiot.
What did you try to make it work?: First I read somewhere to set the image objects to load from the start but have their opacity turned to 0, then have them appear using a code like this
(shock0-2 are objects containing one image each)
(Begin routine)
Shock0.opacity = "0" #start shock0 invisible
Shock1.opacity = "0" #start shock1 invisible
Shock2.opacity = "0" #start shock2 invisible
if event.getKeys('down'): # if down key pushed,
Shock0.opacity = "1.0" # make shock0 appear
elif event.getKeys('left'): # if left key is pushed
Shock1.opacity = "1.0" # make shock1 appear
elif event.getKeys('right'): # if right key is pushed
Shock2.opacity = "1.0" # make shock2 appear
But that didnât work. I donât have the error saved unfortunately, so Iâm sure that I did something wrong. Now when I try to run it the stimulus doesnât start at all. It immediately crashes with no generated output before I get to enter participant ID. So at the moment everything is just commented out for the time being.
Then I was thinking if there is a possibility to connect the start time of each image to which button is being pressed instead. And here I am. Tried looking up online resources but couldnât find anything.
If possible I want to be able to solve it all in the builder, trying to avoid actual coding as much as possible for the time being.
Hello, and thank you @dvbridges and @frank.papenmeier! Your solutions definitely helped and put me in the right direction, and your assistance is greatly appreciated!
My project, however, doesnât seem to respond to the button presses very quickly. The test version you sent me was very fast by comparison. No idea what is causing the slowdown.
The project itself is a setup constructed to send fake electric shocks to no real participant. Preferably I would have one button-pressed evoked image to stay present for the duration of the loop with no other input accepted after the first one.
From what I understand for that to work, I need to, in my key settings, select Store: First Key, and untick Discard Previous?
I will attach the relevant project files. Please put all pictures in a folder named âimagesâ AggPrototypeRetaliationTest.psyexp (30.5 KB)
I think the problem is the way you have combined the event module with the keyboard component. You are better off using one or the other, so I would use keyboard component. You are saving all keys in the keyboard component, and that will affect the logic below, because âdownâ and âleftâ may always be true if both keys are pressed within the trial. You are better off using âlast keyâ and if you really want to save all keys, add them to a list and save that list in your datafile. If this is not acceptable, let us know and we can change things. For now, try âlast keyâ in your keyboard component, and replace your code in the âEvery Frameâ tab of the âRetaliationâ routine code component with:
if 'down' == RetaliationKey.keys: # if down key pushed,
Shock0.opacity = 1.0 # make shock0 appear
Shock1.opacity = 0 # make shock1 invisible
Shock2.opacity = 0 # make shock2 invisible
elif 'left' == RetaliationKey.keys: # if left key is pushed
Shock1.opacity = 1.0 # make shock1 appear
Shock0.opacity = 0 # make shock0 invisible
Shock2.opacity = 0 # make shock2 invisible
elif 'right' == RetaliationKey.keys: # if right key is pushed
Shock2.opacity = 1.0 # make shock2 appear
Shock0.opacity = 0 # make shock0 invisible
Shock1.opacity = 0 # make shock1 invisible