# Forcing staircase to present values from a list

**URL:** <https://discourse.psychopy.org/t/forcing-staircase-to-present-values-from-a-list/43654>\
**Category:** Coding\
**Tags:** data\
**Created:** [January 27, 2025, 11:52am UTC](https://discourse.psychopy.org/t/forcing-staircase-to-present-values-from-a-list/43654 "2025-01-27T11:52:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ali\_shirali](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/ali_shirali/32/44076_2.png) [@Ali\_shirali](https://discourse.psychopy.org/u/Ali_shirali)\
**Post date:** [January 27, 2025, 11:52am UTC](https://discourse.psychopy.org/t/forcing-staircase-to-present-values-from-a-list/43654/1 "2025-01-27T11:52:13Z")

</div>

I want to run a simple staircase to handle a 2AFC test. The user should differentiate velocities between the two moving dot fields presented to them. based on the correct or wrong answer, staircase uses the stepSizes to determine the next velocity.

I have a list of velocities: [+/- 5,10,20,40,80] and I only want to present these values at every test. However the stepsize should change, the final value presented should be one of those values in the velocity list.

How can that be achieved?

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [January 27, 2025, 3:22pm UTC](https://discourse.psychopy.org/t/forcing-staircase-to-present-values-from-a-list/43654/2 "2025-01-27T15:22:02Z")

</div>

I’m not experienced with staircase myself but perhaps this thread will help.

> [@Staircase handler stepSizes parameter - what are the possibilities?](https://discourse.psychopy.org/t/staircase-handler-stepsizes-parameter-what-are-the-possibilities/1746):
>
> Hi, I am trying to write a staircase for a visual perception task. From a previous task I will have calculated a participants particular ‘threshold value’/just noticeable difference value (e.g 40ms), and I am trying to write a programme where I can input the participants threshold value at the start, and then the stair case goes up/down in increments of this threshold (e.g every step up could be 2xthreshold value, and steps down could by 1xthreshold). (I know this probably sounds like a weird r…

Also

> [@Thresholding Freezing Laptop](https://discourse.psychopy.org/t/thresholding-freezing-laptop/34685):
>
> Hello - I’m trying to create a signal detection task. Individuals will hear white noise and need to detect if there is a tone or not. Individual detection thresholds at 75%, 50% and 25% need to be attained (it will eventually be uploaded to Pavlovia - but I’ll cross that path later). So far I’ve kept it simple with three routines: welcome page, thresholding trial, and end screen. In the thresholding trial I’ve uploaded the audio files separately - using the builder. I’ve added a fixation cross…

---

<div class="post-metadata">

**Author:** ![Ali\_shirali](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/ali_shirali/32/44076_2.png) [@Ali\_shirali](https://discourse.psychopy.org/u/Ali_shirali)\
**Post date:** [January 28, 2025, 12:36pm UTC](https://discourse.psychopy.org/t/forcing-staircase-to-present-values-from-a-list/43654/3 "2025-01-28T12:36:23Z")

</div>

Thanks for your response, I went through those two threads but still couldn’t find any answer to my problem.  
The stairHandler class starts with an initial value and uses predefined step sizes to increment/decrement the intensity. In my case, I want only specific intensities to be presented for the 2AFC task i.e. the stepsize should be changing in every iteration I guess (not sure).

so is there any way to force stairHandler to only present values from this list [+/- 5,10,20,40,80]?

---

<div class="post-metadata">

**Author:** ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)\
**Post date:** [January 28, 2025, 1:40pm UTC](https://discourse.psychopy.org/t/forcing-staircase-to-present-values-from-a-list/43654/4 "2025-01-28T13:40:02Z")

</div>

Hello @Ali_shirali

I also do not use the staircase-loops but take a look here [Flow — PsychoPy v2024.2.5](https://www.psychopy.org/builder/flow.html#loops)

Best wishes Jens

---

<div class="post-metadata">

**Author:** ![Kimberley\_Dundas](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/kimberley_dundas/32/32322_2.png) [@Kimberley\_Dundas](https://discourse.psychopy.org/u/Kimberley_Dundas)\
**Post date:** [January 31, 2025, 7:49am UTC](https://discourse.psychopy.org/t/forcing-staircase-to-present-values-from-a-list/43654/5 "2025-01-31T07:49:25Z")

</div>

Hi @Ali_shirali,

Do you mean that you only ever want to use the velocities from that list? If so, I’m wondering if you need to use a staircase at all? Instead, you could just cycle through the velocities and set the next one based on whether the response is correct or not? Then end the loop after a given number of incorrect responses at a certain velocity?

Something like:

```auto
## BEGIN EXPERIMENT ##

vel_list = [5,10,20,40,80] # Initialise your list of velocities
vel_idx = 2 # Start in the middle of the list (for example)
consecutive_correct = 0 # Track correct answers at current velocity
consecutive_incorrect = 0 # Track incorrect answers at current velocity
threshold_correct = 5 # End after 5 correct responses at the same velocity (for example)
threshold_incorrect = 3 # End after 3 incorrect responses at the same velocity (for example)

```

```auto
## BEGIN ROUTINE ##
# Use the current velocity for your stimulus
this_vel = vel_list[vel_idx]

```

```auto
## END ROUTINE ##
# Increase velocity if answer is correct (or decrease - I'm not sure of the behaviour you're looking for
if correct:
     consecutive_correct += 1 
     consecutive_incorrect = 0  
     if vel_idx < len(velocity_values) - 1:
          vel_idx += 1 # Move to a more difficult velocity
# Otherwise, decrease velocity (or increase)
else:
     consecutive_incorrect += 1 
     consecutive_correct = 0 
     if consecutive_correct >= 2 and current_index > 0:
          vel_idx -= 1 # Move to an easier velocity

# End loop if too many incorrect responses at one level
    if consecutive_incorrect >= threshold_incorrect:
        currentLoop.finished = True

```

I’ve not tested the above, but hopefully it’s enough to get you started. Apologies if I’ve misunderstood your goals here!

Kim
