Post by val on Nov 8, 2021 8:11:59 GMT
Hello,
I'm trying to program a version of the "n-back task" (specifically a 2-back task) by modifying the experimental code provided by PsyToolkit.
In the original code, the program would decide whether a trial was "matched" vs. "non-matched" based on randomisation. For some context: "matched" trials are when the letter is the same as the letter 2 trials ago, whereas for "non-matched" trials, the letter is not the same as the one 2 trials ago. Due to this randomisation, the number of matched trials can differ across participants. Please see original code here (focus specifically on the "task twoback" section).
I want to design an n-back task where each block contains 6 matched trials and 14 non-matched trials (20 trials in total). I don't know how else to modify the original code, except to create a tasklist with multiple tasks, for example:
This works, to randomise the order of matched and non-matched tasks across trials. However, I ultimately want my "twoback_match" trials to occur only after the 2nd trial in the full sequence of 20 trials. I have tried coding this within my "task twoback_match" section, but I'm not getting anywhere despite multiple attempts. For example, I get something like this for my sequence of tasks across the first 5 trials:
trial 1: twoback_nomatch
trial 2: twoback_match <-- (I want this to be twoback_nomatch)
trial 3: twoback_match
trial 4: twoback_nomatch
trial 4: twoback_match
Does anyone know how I can work around this? Can I specify something that can tell Psytoolkit to do the following, perhaps within the "block" section?
Please see below for relevant sections of my code of my existing code if you are able to assist. Your help would be greatly appreciated!
Thanks heaps.
--------
My code:
##1) SPECIFY PARTS##
part check_response
if $requiredresponse == 0 and STATUS == TIMEOUT
set $score 1 ## so far so good
fi
if $requiredresponse == 0 and STATUS != TIMEOUT
set $score 0 ## wrongly pressed during letter presentation.
set $false_alarm 1
show bitmap error_feedback ## red rectangle below and over letter
fi
if $requiredresponse == 1 and STATUS != TIMEOUT
set $score 1 ## correctly pressed during letter presentation.
set $match 1
show bitmap correct_feedback ## green rectangle below and over letter
fi
part trial_presentation
draw off
show bitmap $currentletter ## stimulus 1
show bitmap grey_feedback ## stimulus 2
draw on
readkey 1 &stimulus_display_time
set $extrawait expression &stimulus_display_time - RT ## how much time is left between max RT and now?
##############################################################
## determine whether error was made during letter presentation
## people can only make mistake if pressing now when they should not
##############################################################
set $score 0 ## this is the default, assume error
part check_response
set $my_rt RT
###########
## now wait remaining time if needed
###########
delay $extrawait ## wait until letter has been on screen total of 760 ms, note this only happens if people already pressed
clear 1 ## clear the letter from screen
###########
## now show nothing but allow response during ITI
###########
if STATUS == TIMEOUT ## means people did not respond yet
readkey 1 &iti
set $my_rt expression RT + &stimulus_display_time
fi
part check_response
## if you pressed, then some time will be left; during that time, no need to further check keys anymore
set $extrawait expression &iti - RT ## how much time is left between iti RT and now?
## now check if people missed
if $requiredresponse == 1 and $score == 0
set $miss 1
fi
delay $extrawait
### now save the letter for next trial
set &nback2 &nback1
set &nback1 $currentletter
### save the data
save BLOCKNUMBER TASKNAME &trialcount $typeoftrial $score $match $miss $false_alarm $my_rt $currentletter &nback1 &nback2
##2) SPECIFY TASKS##
task twoback_match
keys space
set &trialcount increase
set $currentletter random 1 15 ## choose random letter out of the 15 options
## Define a 2back trial
set $memory 1
if $memory == 1 and &trialcount > 2
set $currentletter &nback2
set $requiredresponse 1 ## the spacebar key needs to be pressed later
set $typeoftrial 1
fi
part trial_presentation
task twoback_nomatch
keys space
set &trialcount increase
set $currentletter random 1 15 ## choose random letter out of the 15 options
## Define a non 2-back trial
set $memory 2
if $memory == 2 or &trialcount <= 2 ## chose a letter but not that of 2 trials ago
set $currentletter random 1 15
while $currentletter == &nback2 ## choose anything but NOT that of 2 back
set $currentletter random 1 15
while-end
set $requiredresponse 0 ## no key should be pressed
set $typeoftrial 0
fi
part trial_presentation
##3)SPECIFY BLOCKS##
block twoback
set &trialcount 0
tasklist
twoback_match 6
twoback_nomatch 14
end
I'm trying to program a version of the "n-back task" (specifically a 2-back task) by modifying the experimental code provided by PsyToolkit.
In the original code, the program would decide whether a trial was "matched" vs. "non-matched" based on randomisation. For some context: "matched" trials are when the letter is the same as the letter 2 trials ago, whereas for "non-matched" trials, the letter is not the same as the one 2 trials ago. Due to this randomisation, the number of matched trials can differ across participants. Please see original code here (focus specifically on the "task twoback" section).
I want to design an n-back task where each block contains 6 matched trials and 14 non-matched trials (20 trials in total). I don't know how else to modify the original code, except to create a tasklist with multiple tasks, for example:
block twoback
set &trialcount 0
tasklist
twoback_match 6
twoback_nomatch 14
end
This works, to randomise the order of matched and non-matched tasks across trials. However, I ultimately want my "twoback_match" trials to occur only after the 2nd trial in the full sequence of 20 trials. I have tried coding this within my "task twoback_match" section, but I'm not getting anywhere despite multiple attempts. For example, I get something like this for my sequence of tasks across the first 5 trials:
trial 1: twoback_nomatch
trial 2: twoback_match <-- (I want this to be twoback_nomatch)
trial 3: twoback_match
trial 4: twoback_nomatch
trial 4: twoback_match
Does anyone know how I can work around this? Can I specify something that can tell Psytoolkit to do the following, perhaps within the "block" section?
- Always present "twoback_nomatch" task for the 1st and 2nd trials of the block (never present twoback_match task for these 2 trials)
- For all trials after the 2nd one (i.e., trials 3 - 20), the order of twoback_match and twoback_nomatch tasks should be randomised
Thanks heaps.
--------
My code:
##1) SPECIFY PARTS##
part check_response
if $requiredresponse == 0 and STATUS == TIMEOUT
set $score 1 ## so far so good
fi
if $requiredresponse == 0 and STATUS != TIMEOUT
set $score 0 ## wrongly pressed during letter presentation.
set $false_alarm 1
show bitmap error_feedback ## red rectangle below and over letter
fi
if $requiredresponse == 1 and STATUS != TIMEOUT
set $score 1 ## correctly pressed during letter presentation.
set $match 1
show bitmap correct_feedback ## green rectangle below and over letter
fi
part trial_presentation
draw off
show bitmap $currentletter ## stimulus 1
show bitmap grey_feedback ## stimulus 2
draw on
readkey 1 &stimulus_display_time
set $extrawait expression &stimulus_display_time - RT ## how much time is left between max RT and now?
##############################################################
## determine whether error was made during letter presentation
## people can only make mistake if pressing now when they should not
##############################################################
set $score 0 ## this is the default, assume error
part check_response
set $my_rt RT
###########
## now wait remaining time if needed
###########
delay $extrawait ## wait until letter has been on screen total of 760 ms, note this only happens if people already pressed
clear 1 ## clear the letter from screen
###########
## now show nothing but allow response during ITI
###########
if STATUS == TIMEOUT ## means people did not respond yet
readkey 1 &iti
set $my_rt expression RT + &stimulus_display_time
fi
part check_response
## if you pressed, then some time will be left; during that time, no need to further check keys anymore
set $extrawait expression &iti - RT ## how much time is left between iti RT and now?
## now check if people missed
if $requiredresponse == 1 and $score == 0
set $miss 1
fi
delay $extrawait
### now save the letter for next trial
set &nback2 &nback1
set &nback1 $currentletter
### save the data
save BLOCKNUMBER TASKNAME &trialcount $typeoftrial $score $match $miss $false_alarm $my_rt $currentletter &nback1 &nback2
##2) SPECIFY TASKS##
task twoback_match
keys space
set &trialcount increase
set $currentletter random 1 15 ## choose random letter out of the 15 options
## Define a 2back trial
set $memory 1
if $memory == 1 and &trialcount > 2
set $currentletter &nback2
set $requiredresponse 1 ## the spacebar key needs to be pressed later
set $typeoftrial 1
fi
part trial_presentation
task twoback_nomatch
keys space
set &trialcount increase
set $currentletter random 1 15 ## choose random letter out of the 15 options
## Define a non 2-back trial
set $memory 2
if $memory == 2 or &trialcount <= 2 ## chose a letter but not that of 2 trials ago
set $currentletter random 1 15
while $currentletter == &nback2 ## choose anything but NOT that of 2 back
set $currentletter random 1 15
while-end
set $requiredresponse 0 ## no key should be pressed
set $typeoftrial 0
fi
part trial_presentation
##3)SPECIFY BLOCKS##
block twoback
set &trialcount 0
tasklist
twoback_match 6
twoback_nomatch 14
end