Don't take key press until slider response is made!

URL of experiment: https://pavlovia.org/Aparna11/wordsound

Description of the problem:
Hi,
In my experiment I have slider response followed by key press (space) to go to next trial. I have observed that sometimes participants are pressing space without responding on the slider. I loose data in such situations. I want to hold the trial until slider response is given then only the “space” press should work to go to next trial.

Can anyone help in this?

Thank you
Aparna

Instead of having your keyboard component force the end of the routine, you need some code in Each Frame

e.g.

if slider.getRating() != None:
      if 'space' in key_resp.keys:
          continueRoutine=False

When this auto translates, you’ll need to switch the component to Both and then change null (the auto translation of None) to undefined

1 Like

or make a start condition for the keyboard: “slider.rating”

Will that work online?

Yes :slight_smile:

1 Like

i used this code on each frame. its giving error message screenshot attached

This works but I have one more key response ‘r’ for repeat. I will have to use code only

Thank you

This works but I have one more key response ‘r’ for repeat. I will have to use code only. but code is giving error message as described before

Thank you

Try

if slider.getRating() != None and len(key_resp.keys):
      if 'space' in key_resp.keys:
          continueRoutine=False
     elif 'r' in key_resp.keys:
          do other stuff

Assuming that r can also only be pressed after the slider rating is set

Hi Aparna, how did you resolve this? I am trying to achieve the same thing and getting the same error as in your screenshot.

Try

if key_resp.keys:
     if 'space' in key_resp.keys:

That does seem to get rid of the error, but it doesn’t seem to result in the intended behavior (prohibiting key press until sliders contain a response).

I have two sliders so it is slightly different from the above example, but it doesn’t seem to work in the minimal case of a single slider either. Any ideas?


s

Try changing the component to Both and then changing null (the Auto translation of None) to undefined

I have actually done that already - line 19 in the screenshot above.

Is there an analog condition for the textbox instead of the slider? I’d like to allow a mouseclick only if the textbox contains something. Thanks!

For the sake of record keeping - I realized the “force end of routine” in the keyboard component was overriding the code component. Of course, once I unchecked that, it worked as expected.

Although I guess a weird thing is that if the participant presses “space” before responding, once both sliders are clicked then it will automatically move on without a key press. The ideal situation would be that the “force end of routine” key press would have to occur after the slider response, so that accidental presses wouldn’t be “counted”.

The way I recently solved this was sliderStarted = False in Begin Routine then in each frame:

if slider.markerPos:
    sliderStarted = True

and then have sliderStarted as the start condition of the keyboard response.

Nice! This totally worked. For anyone trying to achieve this in the future - I had to put this code in a new code component with the “Auto” translation designation to get it all to work properly.

Hello wakecarter,

I am currently using this code and it’s working perfectly fine. The only issue that now occurs is that when a participant wants to use the slider AFTER pressing space it immediately takes the first response on the slider and moving the slider is no longer possible. If you don’t press space before using the slider it’s still working completely normal. How is it possible to fix that so my participants can still change the response on the slider until pressing space to end the routine?

Thanks in Advance!
Tim