What should I do if the first stimulus in the loop is not working, but the rest of the loop is OK?

Hello everyone,
I’m new to Psychopy. I added a code that makes a square polygon appear on the screen when I press the space key, stays on the screen for the time the key is pressed, and goes off the screen when the key is released. I have two separate routines for this process. My polygon component is the same in both routines. Both have code component at the bottom. The begin routine part of the first has

myClock = core.Clock()

and each frame section:

if defaultKeyboard.getKeys([‘space’], waitRelease=False, clear=False):
#print(“Got key press”)
continueRoutine=False

In the each frame part of the second one, this is written;

if defaultKeyboard.getKeys([‘space’], waitRelease=True):
#thisExp.addData(“RT_release”, myClock.getTime())
thisExp.addData(“reproduction”,t)
continueRoutine=False

The system I created works technically. The problem is that when I put these in the loop, the codes do not work as the first stimulus of the loop, the polygon appears on the screen before I press the space key, and when I press it, it disappears directly from the screen. But in the continuation of the loop it works as it should. So it doesn’t give any error. Can you help me on how to solve this problem? Thank you very much in advance for your help.

Hello

did you make the Start-time of the polygon conditional on pressing the space bar?

Best wishes Jens

Hello Jens,

Thank you very much for your interest. No, I set the polygon’s start time to 0.0. Unfortunately, there is nothing that I can define for the start time for this code I designed. Or I don’t know how to do it. Do you have a suggestion?

Sincerely,

Burcu

Hello Burcu

does this toy-program do what you want?

SpacePressed.psyexp (10.8 KB)

I omitted the RT-saving part and used a triangle instead of a square.

Best wishes Jens

1 Like

Hello Jens,

Although this is not exactly what I want, I can say that it opens the way to a solution! Please accept my deepest thanks :slight_smile:

Best regards,

Burcu