Counting number of trials in stair handler

Hi,
I have a staircase up and running in coder (thanks to everyone who has helped get me this far!) but I am wondering how I can get it to count the number of trials. Reason being for the first 10 trials I want to show participants a certain response prompt, then change to a different prompt for the next 10 trials, and so on.
The basic gist of the staircase is this:

staircase = data.StairHandler(startVal = (4*threshold),
                          stepType = 'lin', stepSizes= [2 , 1 ], 
                          minVal=1, #maxVal=30,
                          nUp=1, nDown=2,  
                          nTrials=40, nReversals=4)

And this is a snippet from my prompt presentation sequence where I want to tell it to do different things depending on what trial number it is on:

for frameN in range (correctStim):
        reminder.draw()
        leftIcon.draw()
        rightIcon.draw()
        leftText.draw()
        rightText.draw()
        if **_thisN <10:_**
            tickIconB.draw()
            win.flip()
        elif **_thisN >=10:_**
            tickIconC.draw()
            win.flip()

I know the ‘thisN’ parts are wrong. The error report tells me I have not defined thisN. But I am struggling to know what code to put in (and where) to help me create a variable that counts the trial number.

If anyone can point me back on track that would be fantastic.
Thanks,
Christina

https://discourse.psychopy.org/t/please-surround-python-code-with/1775

1 Like

Good to see things are working.

thisN is an attribute of your staircase handler, so if you replace your thisN with staircase.thisN you should be OK!

Apologies Jon, I have edited my post. Thanks!

Jan, I tried staircase.thisN but it seems that ‘thisN’ is not actually a stairhandler attribute afterall.
There is a similar sounding attribute ‘nTrials’ , but this is just the minimum number of trials in the staircase, it is not keeping count as trials progress. Trying staircase.nTrials ran ok, but obviously did not work in the desired way.

Would you have any other suggestion of a way round this? I can’t see a suitable looking stairhandler attribute.
Thanks!

1 Like

I fixed it!!! :champagne:

It was thisTrialN I wanted

for frameN in range (correctStim):
        reminder.draw()
        leftIcon.draw()
        rightIcon.draw()
        leftText.draw()
        rightText.draw()
        if staircase.thisTrialN <10:
            tickIconB.draw()
            win.flip()
        elif staircase.thisTrialN >=10:
            tickIconC.draw()
            win.flip()

Works perfectly now.
Thanks for your continuing support guys!

2 Likes