| Reference | Downloads | Github

Set Rating scales to mandatory

Hi there,
I have a routine with two rating scales (gender and age).
The end of the routine will be forced by pressing the right arrow key.

OS Win10
PsychoPy version 3.0.5
Standard Standalone? y

What are you trying to achieve?:
I want to achieve that it is not possible to force the end of the routine before the ratings have been made. Here is my current setup:

What did you try to make it work?:
Am I right that I have to insert a code component that checks if the variables ‘gender’ and ‘age’ have assigned values? If so, how is it possible to do that?


Hi @Fabian, I would advise that you use the new Slider scale . The Slider has an option to end routine on rating, so you can just deselect that option and the routine will continue after each rating. Slider also available to use in your online studies.

Hi @dvbridges,
the same option exist for the ‘old’ rating component. I have already deselected this. Actually, I want to avoid that the participants can skip this page by just using the right arrow key to go to the next routine without a rating. So, I want to force them to do the rating. Just deselecting the option to end routine after each rating would not prevent that.

Ok, great. Well then you would want to check whether a rating has been given, and if so, check the keyboard:

# On every frame
if gender.getRating() is not None and age.getRating() is not None:
    if Personnel_FeoR.keys == 'right':
        continueRoutine = False

1 Like

Perfect, thanks! This works. :slight_smile:


I’ve been looking to do the same as above and make it compulsory that a participant selects their gender before being able to continue with the experiment.
Based on the above I’ve used the following code:

if SelectGender.getRating() is not None:
if Continue2Age.keys == ‘space’:
continueRoutine = False

SelectGender is the name of my slider and Continue2Age is the name of my response key but this doesn’t seem to be working and I can still continue the routine without selecting anything.

Is anyone able to advise?

@newbie2, have you deselected the option in keyboard and slider to end trial on response?

I did try this but when I removed the force end of routine option in the keyboard, the routine won’t regardless of whether or not a response has been made.

If you go to your keyboard, and make sure that ‘space’ is an allowed key, and that Store is set to last key, and the duration of the keyboard is infinite (blank). Then in your code components “Each Frame” tab:

if SelectGender.getRating() is not None:
    if Continue2Age.keys == ‘space’:
        continueRoutine = False

# Clearing these makes sure no previous keypress can end the trial after a rating is made
Continue2Age.keys = []  
Continue2Age.rt = []

Hi @newbie2,

here is my solution if you are interested (Each frame):

keys = event.getKeys()

if 'space' in keys:
    completed_ratings = 0
    for slider in [r1, r2, r3, r4, r5, r6, r7, r8, r9, r10]:
        if slider.getRating() is not None:
            completed_ratings = completed_ratings + 1

    if completed_ratings == 10:
        continueRoutine = False

I have ten ratings (r1, r2, …, r10) in this routine. The if-function checks if each rating has a “completed_rating”. Only if “completed_ratings == 10” the participant is able to end the routine by pressing the space bar.

1 Like

This worked for me too!! I just used the name of my 4 sliders and added a keyboard item (without force clicked) and then this in the everyframe of a code portion, as you outlined. Thank you for sharing!

I’ve found an error with this method-- The screen won’t move on unless all 4 ratings have a marker on them, but even without clicking the bar (just hovering over and showing the marker) the slider.getKeys function views the rating as “pressed” (even though the csv data then says “None” still in the field. Does anyone know why this happens or how to prevent it?

Thank you!

Hi @Casey_Jayne, can we see your code? Hovering over the slider should not make a selection on the slider.


IMG_1208|240x320 IMG_1207|240x320

You can see in the data output that it’s being coded as “None”. Here is a video of how it looks when it allows me to skip vs. when it doesn’t. I have the sliders coded to disappear when an answer is pushed:

{{ it won’t let me upload a video, is there a suggestion how I can share that? }}

Ah, I see. I would recommend switching to the Slider component, its a modern version of rating scale that is simpler to use and configure. My code above assumed you were using Sliders.

Hi @dvbridges,
thank you for this response. I believe I am using the Slider component-- that’s what is says in Builder. What makes you think that I’m not? When I look up slider here that is what I am using.

Thanks for clarifying,

Hi @Casey_Jayne, I say this because the icons in your first image are of the rating scale.

Here is rating scale component:

Here is Slider component:

Hi @dvbridges,

You’re right, I found out what you were referring to. However, the slider doesn’t allow me to set to “single click”, change the marker type, or set “disappear=True”. I tried adding directly into the builder code and it says invalid syntax.

I’ve tired some custom code to make the element disappear but it doesn’t work either.

In a new “Each Frame” coder component:

for slider in [slider_1]:
   if slider.getRating() is not None:
        if completed_slider=1:

This code doesn’t break the script, but it also doesn’t do anything.