Stop updating Slider Marker Position

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): v2021.1.2
Standard Standalone? (y/n) yes
What are you trying to achieve?:
I want my participants to give a rating on a visual Scale from 1 to 10, using the slider component (“AttractivenessSlider”) and keyboard presses to move the marker (I added this with a code component & save the marker Position in my csv). After they have placed the marker at the desired position using the ‘7’ and ‘9’ keys, they should “log in” their response using the ‘8’. After that I want the scale to disappear, leaving only the question on the screen until the routine is ended after 5 seconds.
Notes: I want the routine with the rating to have a set length, so “force end of routine” is no option.

What did you try to make it work?:
First I looked for an attribute like “lock” or “stop updating” for the marker Position but couldnt find anything.
In the slider component I set the stop parameter to “condition” and added “event.getKeys(‘8’)”. That worked in terms of ending the slider component when 8 is pressed and making the screen look like I want it.

What specifically went wrong when you tried that?:
Unfortunately, even after the slider disappeared from the screen (as desired), the marker position is still affected by button presses of 7 and 9 (I assume due to my custom code component).
So if participants were to play around with the keys after logging their response, my data will still be changed and not show their actual response.

Begin Routine Tab

event.clearEvents('keyboard')
AttractivenessSlider.markerPos = 5

Each Frame Tab

keys = event.getKeys()

if len(keys):
    if '7' in keys:
        AttractivenessSlider.markerPos = AttractivenessSlider.markerPos - 1
    elif '9' in keys:
        AttractivenessSlider.markerPos = AttractivenessSlider.markerPos + 1

Additionally
I tried storing the marker position in the slider.response when ‘8’ is pressed (since the response parameter is not affected by the marker position, I wanted to treat it as my own variable for storing the response).
This works but only gives me the response in the rating variable if the participant actually confirms by pressing ‘8’. If they dont, I only have it in the marker Position variable, which makes Data processing and analysis really complicated.
I also played around with various if, if not, etc. statements in the end routine Tab but there it did not do anything, apparently (I tried to store the marker position in the response variable when “time was up” and the participant hadn’t pressed 8)

if '8' in keys:
AttractivenessSlider.rating = AttractivenessSlider.markerPos

I feel like I tried everything I could think of but nothing works quite the way I need it. I would really appreciate any input! :slight_smile: Thank you all in advance!

Hi @ElenaLosse, how about changing your code from

if len(keys): ...

to

if len(keys) and !('8' in event.getKeys()):...

?

This if would probably also have to include the keys = event.getKeys() so your keys don’t get refreshed after an 8 has been pressed. This way any change to the slider would only be possible as long as 8 has not been pressed. Hope that helps! Adrian

Thinking about it, maybe this does not work. It’s probably easier to have a list of keypresses that is amended with the last key press every time a key is pressed. For this, you could then check if it contains an 8.

So something like

Begin Routine Tab

event.clearEvents('keyboard')
AttractivenessSlider.markerPos = 5
keypresses = []

Each Frame Tab

keys = event.getKeys()

if len(keys) and !('8' in keypresses):
    keypresses.append(keys)
    if '7' in keys:
        AttractivenessSlider.markerPos = AttractivenessSlider.markerPos - 1
    elif '9' in keys:
        AttractivenessSlider.markerPos = AttractivenessSlider.markerPos + 1
1 Like

Hi @ajus thank you for your ideas! Unfortunatley neither of the two did anything as far as I can tell (I can still change the marker position after pressing ‘8’).
I also tried it like this, but with the same result… (and treid adding/ leaving out the () etc.)
btw. I think python does not accept ! but wants a “not”
do you have any other ideas? :slight_smile: I dont really understand why this isnt working…

keys = event.getKeys()


if len(keys):
    keypresses.append(keys)
    if '7' in keys and not '8' in keypresses:
        AttractivenessSlider.markerPos = AttractivenessSlider.markerPos - 1
    elif '9' in keys and not '8' in keypresses:
        AttractivenessSlider.markerPos = AttractivenessSlider.markerPos + 1

That is weird indeed. To troubleshoot, you could print all relevant variables to the console and see at which point it fails:

keys = event.getKeys()


if len(keys):
    print(keys)
    keypresses.append(keys)
    print(keypresses)
    print(not '8' in keypresses)
    print('7' in keys and not '8' in keypresses)
    print('9' in keys and not '8' in keypresses)
    if '7' in keys and not '8' in keypresses:
        AttractivenessSlider.markerPos = AttractivenessSlider.markerPos - 1
    elif '9' in keys and not '8' in keypresses:
        AttractivenessSlider.markerPos = AttractivenessSlider.markerPos + 1
1 Like

I’m sorry, I am not so familiar with programming, I am not sure how to use and interpret this code…
I put it in the “each frame” Tab
and while running I pressed 7, 7, 8, 9 and got the following in the console:

[‘7’]
[[‘7’]]
True
True
False
[‘7’]
[[‘7’], [‘7’]]
True
True
False
[‘8’]
[[‘7’], [‘7’], [‘8’]]
True
False
False
[‘9’]
[[‘7’], [‘7’], [‘8’], [‘9’]]
True
False
True

Does this tell you anything? :see_no_evil: :slight_smile:

Oh wow I think I got it!
I just had to add the brackets to the “and not” statement. So with the following code, the slider does not change anymore once ‘8’ was pressed!
Thank you so much!!!

keys = event.getKeys()

if len(keys):
    keypresses.append(keys)
    if '7' in keys and not ['8'] in keypresses:
        AttractivenessSlider.markerPos = AttractivenessSlider.markerPos - 1
    elif '9' in keys and not ['8'] in keypresses:
        AttractivenessSlider.markerPos = AttractivenessSlider.markerPos + 1

Cool! So apparently append did not work exactly as I expected. But great, that you figured it out!

Yes I really think this is it. Thanks again for helping me, this is great! :slight_smile: All the best!