# Staircase error

**URL:** <https://discourse.psychopy.org/t/staircase-error/39469>\
**Category:** Builder\
**Created:** [April 5, 2024, 5:12pm UTC](https://discourse.psychopy.org/t/staircase-error/39469 "2024-04-05T17:12:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![terronymous-boosh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/terronymous-boosh/32/1431_2.png) [@terronymous-boosh](https://discourse.psychopy.org/u/terronymous-boosh)\
**Post date:** [April 5, 2024, 5:12pm UTC](https://discourse.psychopy.org/t/staircase-error/39469/1 "2024-04-05T17:12:32Z")

</div>

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

**OS** (e.g. Win10): Win 10  
**PsychoPy version** (e.g. 1.84.x): 2023.2.3  
**Standard Standalone? (y/n)** y  
**What are you trying to achieve?:** insert a staircase loop

**What did you try to make it work?:** inserted a staircase loop, put in the values, clicked on run

**What specifically went wrong when you tried that?:**  
Error window appeared with the following text:

Traceback (most recent call last):  
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\app\builder\builder.py”, line 1275, in runFile  
self.app.runner.panel.runLocal(event)  
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\app\runner\runner.py”, line 749, in runLocal  
generateScript(experimentPath=currentFile.replace(‘.psyexp’, ‘\_lastrun.py’),  
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 91, in generateScript  
compileScript(infile=exp, version=None, outfile=filename)  
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 229, in compileScript  
\_makeTarget(thisExp, outfile, targetOutput)  
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 209, in _makeTarget  
script = thisExp.writeScript(outfile, target=targetOutput)  
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\experiment\_experiment.py”, line 301, in writeScript  
self\_copy.flow.writeBody(script)  
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\experiment\flow.py”, line 304, in writeBody  
entry.writeMainCode(script)  
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\experiment\routines\_base.py”, line 537, in writeMainCode  
event.writeRoutineEndCode(buff)  
File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\experiment\components\slider\_init_.py", line 389, in writeRoutineEndCode  
buff.writeIndented(code % (loopName, name, name))  
UnboundLocalError: local variable ‘loopName’ referenced before assignment

---

<div class="post-metadata">

**Author:** ![terronymous-boosh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/terronymous-boosh/32/1431_2.png) [@terronymous-boosh](https://discourse.psychopy.org/u/terronymous-boosh)\
**Post date:** [April 5, 2024, 5:27pm UTC](https://discourse.psychopy.org/t/staircase-error/39469/2 "2024-04-05T17:27:49Z")

</div>

Identical behaviour in 2024.1.1

---

<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:** [April 5, 2024, 6:32pm UTC](https://discourse.psychopy.org/t/staircase-error/39469/3 "2024-04-05T18:32:57Z")

</div>

Does loopName appear in your code?

Please could you show your flow and you staircase?

---

<div class="post-metadata">

**Author:** ![terronymous-boosh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/terronymous-boosh/32/1431_2.png) [@terronymous-boosh](https://discourse.psychopy.org/u/terronymous-boosh)\
**Post date:** [April 7, 2024, 4:31pm UTC](https://discourse.psychopy.org/t/staircase-error/39469/4 "2024-04-07T16:31:25Z")

</div>

Hi,

I have no idea where the loopName variable comes from…

Flow is shown below (split in half):

 ![flow_first](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/9/2/92708c9f2540a2fa7a8841909c456dc4c7db7ed3.png)

 ![flow_second](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/f/e/feb063d24e73e11c430e78c415d8bac529cef1a5.png)

The first loop (“practice”) is a standard ‘sequential’ loop controlled by an excel file.

The second loop (“painStairs”) is where I’ve tried (and failed) to use a simple staircase (see parameters below).

 ![staircase](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/2/0/20f45d1de99b9991cfb7225064384c1fb6a7798a.png)

Please note that whilst the numbers in the nUp nDown might look weird - when using more typical values 1 and 3, respectively, the code still fails (same error).

The slightly unusual thing about my intended use for the staircase is that I start with a low level (as this will be used as the temperature of a thermode applied to the skin), and **increase** until a critical value (pain rating) has been exceeded. So, I don’t have a two choice scenario, e.g. where a subject can either detect a difference in the orientation of a grating, or not. Instead the subject provides a rating with a slider object, using a keyboard object (keyResp2) to collect responses (‘left’ or ‘right’) in the routine getRating2. Whilst there is no correct or incorrect answer _per se_, I have a little bit of code in getRating2 that at the end of the routine, determines if the reported pain level is **above** the required level and sets keyResp2.corr = 1, or keyResp2.corr = 0 otherwise. So the idea is that once you’ve exceeded the required threshold, $level should **not be repeated** and instead should be reduced, and keep reducing if the subject continues to report pain levels above the desired level, until they are below the threshold, where they should reply 2 or 3 times with ratings below the desired pain level before the temperature rises again (with the next step on the threshold ladder). Rinse & repeat…

Sorry about the lengthy explanation…

Best wishes,

Jon

FYI if I use an “interleaved staircase” with excel file configured as per the settings above, it seems to work.
