n-Back Test with random letters/numbers

I am using the tutorial to try to code a 2-back test with random letters. I have only found an already opened topic here but there the issue could also not been solved.
I have tried to work through the tutorial and used the code as they used it.

This is the code i tried to run:

presentedLetters =
thisLetter = np.random.choice(letters)
presentedLetter.append(thisLetter)

n = 2
letterSelected = False
if not target:
while not letterSelected:
thisLetter = np.random.choice(letters)
if len(presentedLetters) < n or thisLetter != presentedLetters[-n]:
letterSelect = True
else:
thisLetter = presentedLetters[-n]
presentedLetters.append(thisLetter)

when running the experiment the run fails, with the error message “Indentation Error: expected an indent block” hat the location of the first thisLetter. My code is in the BeginRoutine Tab.
I tried to use different indentations, but i am fairly new to python and psychopy and my tries were unsuccessfull.
Does anybody know a solution?

Kind Regards!

1 Like

If anyone else is still having this problem, i solved it selecting distinct letters (in my case 5 vocals and 5 consonants) and put them in the letters list.

In the begin routine tab i could the run the following code:

n = 2
letterSelected = False

if not target:
    while not letterSelected:
        thisLetter = np.random.choice(letters)
        if len(presentedLetters) < n or thisLetter != presentedLetters[-n]:
            letterSelected = True
else:
    thisLetter = presentedLetters[-n]

presentedLetters.append(thisLetter)

The Presented Letter list was assigned in the begin experiment tab.

1 Like