psychopy.org | Reference | Downloads | Github

How to build a 2-back task with feedback?

OS: win10
PsychoPy version: 2021.1.4

Hi everyone,

I am trying to conduct a basic two-back task that contains 15 letters, which are ‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘H’, ‘I’, ‘K’, ‘L’, ‘M’, ‘O’, ‘P’, ‘R’, ‘S’ and ‘T’.

Every letter would be presented for 500 ms and the participants have 2500 ms to react. Participants have to press the ‘space’ if a letter was presented two trials ago; if not, they don’t have to do anything until the next match.

If a participant correctly responded to the stimulus, there would be a “Correct!” feedback showing on the screen right after responding. If one wrongly responded to the stimulus, there would be a “Wrong!” feedback showing on the screen right after responding.
I have two blocks in my task that one block is for practice, which is called “practice_section” and the other is formal test, which is called “formal_section”
I have followed some ways and tips online to try to conduct the task but there were still some problems.
The fist problem is that trials can not carry on to the next trial automatically unless I press the ‘space’.
The second problem is that the feedback messages in my task is never showed up.

Here is my “practice_section” builder.

Here is my “practice_section” code in code component.

Here is my “practice_section” text component properties.

Here is my “practice_section” keyboard component properties.

Here is my “feedback” builder.

Here is my “feedback” code component.


Here is my “practice_section_trial” properties window.

I am still working on the practice section so I have not built the formal section routine yet.

Any advice will be helpful for me.
Thank you for your time.

Hi,

for your first problem ( trials can not carry on to the next trial automatically unless I press the ‘space’) I don’t know what is causing the problem, as each trial should end after 3 seconds.

As for the rest here are my suggestions:

  1. You can use the same routine for the practice and the formal routine, using two different loop and two different .xlsx file
  2. You can use a lot less code if you specify more thing into your .xlsx files. These is an example of a .xlsx file I am using for a 3-back task 3back_practice.xlsx (9.2 KB)
  3. For example you can tell the keyboard component to register the correct response ($StimAnswer) and it is very easy to analyze the data
  4. Here is how I coded for the feedback, I have a similar routine with a code component and a text component called “text_feedback”. The text component has a variable duration ($msg) and text ($feedback_duration):
if StimAnswer == "d": #if the image is a target
    feedback_duration = 0.5 #show the feedback message for 500 msec
    if key_resp_practice.corr: #if you pressed d show a green positive feedback
        msg = "Corret!"
        text_feedback.color = [-1.000,1.000,-1.000]
    else: #if not, show a red negative feedback
        msg = "Wrong!"
        text_feedback.color = [1.000,-1.000,-1.000]
else: #if the image is not a target
    if key_resp_practice.corr: #if you correctly did not respond don't show anything
       feedback_duration = 0
    else: #if you responded, show a red negative feedback for 500 msec
        feedback_duration = 0.5
        msg = "Wrong!"
        text_feedback.color = [1.000,-1.000,-1.000]

Hope this helps!

1 Like

@tandy It’s working!! Thank you very much!
But there is a little problem that no matter it was a correct answer or not, all the feedback would be “Wrong!”. Did I do something wrong?
Here is my practice_section code component.

# Begin Routine
one_back = []
if trials.thisN == 0: 
   two_back = practice_letters # initial value needed for trial 2
elif trials.thisN == 1:
   one_back = practice_letters # need this to swap with two-back on later trials
elif trials.thisN > 2: # need to update the n-back values
   two_back = one_back
   one_back = practice_letters
if practice_letters == two_back:
   corrAns = "space"
else:
    corrAns = ""
# End Routine
one_back = practice_letters
two_back = one_back

And here is my code component in feedback routine.

#Begin Experiment
msg = ''
#Begin Routine
if corrAns == "space": #if the image is a target
    feedback_duration = 0.5 #show the feedback message for 500 msec
    if key_resp_practice.corr: #if you pressed space show a green positive feedback
        msg = "Correct!"
        text_feedback.color = [-1.000,1.000,-1.000]
    else: #if not, show a red negative feedback
        msg = "Wrong!"
        text_feedback.color = [1.000,-1.000,-1.000]
else: #if the image is not a target
    if key_resp_practice.corr: #if you correctly did not respond don't show anything
       feedback_duration = 0
    else: #if you responded, show a red negative feedback for 500 msec
        feedback_duration = 0.5
        msg = "Wrong!"
        text_feedback.color = [1.000,-1.000,-1.000]

I was wondering if I sat something wrong in the text properties. So this is my text properties looks like.

Any advice would be appreciated.
Thank you!

I think the problem is that in my code I used a keyboard properties to identify which answer was the correct one ($StimAnswer in the .xlsx file), so “key_resp_practice.corr” reads from a column of 1 and 0. So if you want to use another method you need write in your code a way to check the participant’s response

1 Like

@tandy Thank you again!
But I did set a correct answer in the keyboard properties, did I miss something?
This is my keyboard properties looks like.

And this is the corrAns column in my excel file.

Thank you!