psychopy.org | Reference | Downloads | Github

Force Response for Slider

Hi all,

As I found in several posts, in order for the slider to be drawn in online experiments, we need to define another component (say a mouse and a box with the label of “NEXT”) so participants first respond to the slider and then click on the box. The problem with this method is that if someone clicks on the box, it will go to the next trial, without responding to the slider.

I used the following code to stop this and it works. However, now if someone clicks on the screen before the mouse and box appear (which they appear after 5 secs), then the map undefined error would show.

// continue if both slider and mouse is clicked
if (mouse_confidence.getPressed()[0] === 1) { 
  clickable = [save_box];
  for (const obj of clickable) {  // for each clickable stim, check if it contains the mouse
    if (obj.contains(mouse_confidence)) {
      if (obj === save_box && slider_confidence.getRating()) {
         continueRoutine = false;
      } else {
        continueRoutine = true;
       }
    }
  }
}

Any idea on how to solve this problem? Thanks.

@Omidrezaa, you could check the status of the mouse, and only continue with your block of code if the mouse has started i.e., after 5 seconds, when the mouse start time has passed. E.g.,

if (mouse_confidence.status === PsychoJS.Status.STARTED && mouse_confidence.getPressed()[0] === 1) {
    // continue
1 Like

If you’re in Builder, you can maybe set your mouse component to start on “condition” (instead of time) and set this condition to slider.rating (change “slider” to the name of your slider). I used a key component and it worked perfectly.

2 Likes

Hi @dvbridges. Your suggestion solved the cannot read sth of undefined error, However, the beginning problem is still there. I mean, if I set the mouse as Never End Routine, clicking the box would not end the routine and if I set it as End Valid Click, it will end the routine without checking for slider ratings.

Here is the edited code in the Each Frame Tab:


// continue if both slider and mouse is clicked
if (mouse_confidence.status === PsychoJS.Status.STARTED && mouse_confidence.getPressed()[0] === 1) { 
    clickable = [save_box];
      for (const obj of clickable) { 
        if (obj.contains(mouse_confidence)) {
          if (obj === save_box && slider_confidence.getRating()) {
             continueRoutine = false;
} else {
    continueRoutine = true;
            }
        }
    }
}


Hi @lcrible. Thank you for your response. I am afraid that I need to set my mouse to start at a specific time, not a condition. However, I really interested to hear about your solution a bit more. What do you mean by a mouse starts on a condition? And, could you please share the code that you used to set the condition to the slider? I am sure that I can use your solution in other parts of my experiment.

Sure, but I’m only using Builder, not Coder, so I don’t know what the exact code is. But in Builder view, you can change the “start” parameter of a key (and possibly mouse) component to “condition”, and in the box set this condition to “slider.rating”, see in this screen capture. Hope this helps.

3 Likes

@lcrible, your solution was fantastic. I was not aware of setting Start to a condition. Your suggestion solved my problem. i just did a minor change to make it compatible with psychoJS, instead of psychopy, so I used slider.getRating() instead of slider.rating as the condition.

I won’t close the forum now and wait for David’s reply. I am sure I can learn a different approach there.

Thank you.

1 Like