Component (circle) to start following slider response as a highlight of response

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): Windows 11
PsychoPy version (e.g. 2024.2.4 Py 3.8):
**Do you want it to also run online? Yes
What are you trying to achieve?:
Hi,

I am trying to update my cognitive task such that, when someone presses a key slider response using number keys (1,2,3,4,5) to select the confidence rating, I want the number they selected to be highlighted and then they need to press space or enter to confirm their selection
I am therefore, struggling to find a way to highlight the number they have selected after their key press.

What did you try to make it work?:

So far I have set the key_resp_slider to not force end the routine and store the responses. I have added a second keyboard component to confirm the selection. I then created a circle component which im trying to get it to start after there is a key_slider response, to circle over the number that was selected.

Hello @radi

I created a slider component using the PsychoPy defaults, expect that I do not store the rating and do not end the routine. I added a keyboard with ‘space’ as the only key. It starts when a rating has been given.

In addition, I added a code component to the top of the routine with the following tabs:

Begin routine:

slider_response = 0

Each frame:

keys = event.getKeys()

if len(keys):
    if '1' in keys:
        slider.markerPos = 1
        slider_response = slider.getMarkerPos()
    elif '2' in keys:
        slider.markerPos = 2
        slider_response = slider.getMarkerPos()
    elif '3' in keys:
        slider.markerPos = 3
        slider_response = slider.getMarkerPos()
    elif '4' in keys:
        slider.markerPos = 4
        slider_response = slider.getMarkerPos()

and End routine

thisExp.addData('slider_response', slider_response)

This highlights the rating as it is set in slider appearance

Best wishes Jens

Thank you for the help,

I got this error when trying to run it

slider_response = slider.getMarkerPo()
AttributeError: ‘Slider’ object has no attribute ‘getMarkerPo’

Did you accidentally write slider_response = slider.getMarkerPo() instead of slider_response = slider.getMarkerPos()?

i think so,

It works now! Thank you both!

Hello,

I’ve tried to push it to pavlovia and I am getting error in this line

if (((slider.getMarkerPos() != None)) && key_resp_17.status === PsychoJS.Status.NOT_STARTED)

not sure how to fix it.

Use a flag.

Begin Routine

showKeyboard = False

Each Frame

if not showKeyboard and slider.getMarkerPos():
     showKeyboard = True

Then put showKeyboard as the condition.

However, before that try just having slider.getMarkerPos() as the condition. The error is probably because None isn’t getting translated but I don’t think you need it.

1 Like

Hello

I added the start condition to prevent participants to press spacebefore giving a rating. But there are other solutions for this problem.

Best wishes Jens

I tried just this slider.getMarkerPos() and it worked, thank you!