Creating an n-back task in builder view

Hello everyone - I am new to Psychopy, and was wondering if anyone would be able to give me some advice on how to create an n-back task with pictures in builder view on PsychoPy version 1.84.2.

I’m looking to create a 2-back task. I think I just need to work out what parameters to set. I want participants to respond when the stimulus in front of them at any given point is the same as two back, and want to record response times and accuracy. Any advice?

Thanks in advance!

This sort of question suggests you would benefit from the workshop!

http://www.psychopy.org/resources/workshops.html#bep

Hello Kod25, were you successful at creating the task? if yes can you help me out?

Hi Abdul,

You need to ask a specific question here to get a useful answer. Describe exactly what you want to do, what variable you need to refer to in the n-back task, how subjects will give their response, how you will control the variables from your conditions file (e.g.a random order or a fixed, sequential order), and so on.

People generally won’t invest time answering a very general question because the answer almost certainly won’t apply to your specific needs.

Thank you Michael,
My design is same as what Kod25 wanted to do. I want to create 2 conditions, 1st condition shall be 2-back (where the subject will have to indicate whether the image presented is same or different with the image presented 2 back), and the second condition 3-back (where the subject will have to indicate whether the image presented is same or different with the image presented 3 back). I want to record response time and accuracy as well.
I therefore need an assistance on how to create that using the builder view. Thank you

As above, how will you control the variables from your conditions file (e.g.a random order or a fixed, sequential order)?

it will be presented in random order.

OK, in that case, we need to use code to keep track of what the value of a variable was n trials ago.

Insert a code component in your trial routine and put something like this in the Begin routine tab (am assuming you loop is called trials, and you will replace your_variable with whatever is needed):

# keep track of the variable that was current two trials ago:
if trials.thisN == 0: 
    two_back = your_variable # initial value needed for trial 2
if trials.thisN == 1:
    one_back = your_variable # need this to swap with two-back on later trials
if trials.thisN > 2: # need to update the n-back values
    two_back = one_back
    one_back = your_variable

# set whatever keypress values are appropriate for this trial:
if your_variable == two_back:
    correct_response = 'y'
else:
    correct_response = 'n'

Use the correct_response variable in your keyboard component to judge whether the right key as pressed.

You might need to skip the response collection on the first two trials (0 and 1). If so, put that stuff in a separate routine, and in a code component, put this in its Begin routine tab:

if trials.thisN <2:
    continueRoutine = False

Thank you very much Michael.

Hello Michael and everyone,

There has been a change in my task design. Please I need an assistance once again.

I have 80 sets of images to present to the participants in a 2 n back task. I will have 2 blocks. So in first part, I will present 80 pictures, followed by a break then I present another set of 80 pictures to the participants.

Their task is to compare whether the current picture matches with the picture presented 2 back in terms of emotional valance. That is, if the two pictures match as positive emotional expression or negative emotional expression.

The right key should be pressed when there is a match, and the left key pressed when there is no match.

The pictures will be presented sequentially. However, I want the order of the blocks to be presented randomly for each subject .

I need to record their accuracy and response time.
Thank you

Please ask an actual question.

Please Micheal I’m sorry I did not quite get you with what you meant by actual question. The narration above is the full description of what I intend doing in a visual 2 n-back task. I’ve been struggling for hours now trying to use the builder to organize it but I still don’t get it. If I can be assisted with the code to help me programme it I will be grateful. Thank you

I have finally been able to find my way out. Thank you

Hi, me too I’m trying to do a n-back task in builder view.

I was thinking about using letters for my variables (A,B,C,D,E). I will like that letters appear randomly and every time a letter appears, the participant would have to press (y) if 2 letters before it was the same letter that appear or (n) if not.

Do I have to create an excel file with the letters and all the possible combinaisons (AB, AC, AD, AA,…) and with an other column for the answers ? (y,n)

I wrote the code previously given in the code component.

Any help would be appreciated.

Thanks in advance.

And what happened? You need to describe your actual problem.

I get this error:

if trials.thisN == 0

SyntaxError: invalid syntax

That example code was missing some necessary colons. Now corrected above, to read for example:

if trials.thisN == 0:

Thanks.
I’m sorry for all those questions.
I modified the code. I still get an error.

NameError: name 'trials' is not define 

Where do I write my letters ? I tried with an excel file, but it’s not working. I don’t understand what I’m doing wrong

Thanks again

  • this is assuming you have a loop called trials. If it is called something else, use that name instead.
  • make sure the code isn’t in the “Begin experiment” tab: the loop won’t have been created at that stage. It needs to be in the “Begin routine” tab.
1 Like

Finally I changed a bit my code because the same letter two back was not appearing enough… so I need to ‘help’ the system.

I wrote this code :

import string
letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L']
my_list = [random.choice(letters) for _ in range(2)]  # initializing; first two elements have to be random
n = 50  # select the length of the list; note that 2 elements are already inside!
for i in range(n):
  if random.random() < 0.15:  # 15% of the time repeat a letter
    my_list.append(my_list[len(my_list)-2])
  else:
    my_list.append(random.choice(letters))  # 85% of the time, get a new 

So when I am now able to generate a list of letters that 15% of the time the letter 2 back is the same…

I tried to put this code in the code component but after that I was not able to make run my experiment.

Because I want one letter at the time to appear.

Thanks for your help