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!

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.

Hello,

Do you have the complete experiment code for this experiment and would it be possible for you to share it with me?

Thanks!

Hi @superhenrikke,

You first need an excel sheet with a column “target” which contains either a 0 (not target) or a 1 (target).
If you later go through this column and a 1 is encountered the code below selects a letter that was presented n trials before.

In the Begin Experiment Tab you need to specify a list of letters and an empty List to store the presented letters. Like this:

letters = ['A', 'E', 'I', 'O', 'U', 'P', 'Z', 'C', 'D', 'M']

presentedLetters = []

The in the Begin Routine Tab you specify how many trials back you need to match and specify a control variable “letterSelected” to be FALSE:

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 rest of the code should automatically, based on your n, choose a letter to be target or not target.

Hope that helps:)
Best, Jan