Staircase error

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\”, line 1275, in runFile
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\app\runner\”, line 749, in runLocal
generateScript(experimentPath=currentFile.replace(‘.psyexp’, ‘’),
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\scripts\”, line 91, in generateScript
compileScript(infile=exp, version=None, outfile=filename)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\scripts\”, line 229, in compileScript
_makeTarget(thisExp, outfile, targetOutput)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\scripts\”, line 209, in makeTarget
script = thisExp.writeScript(outfile, target=targetOutput)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\”, line 301, in writeScript
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\experiment\”, line 304, in writeBody
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\experiment\”, line 537, in writeMainCode
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

Identical behaviour in 2024.1.1

Does loopName appear in your code?

Please could you show your flow and you staircase?


I have no idea where the loopName variable comes from…

Flow is shown below (split in half):

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).

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,


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