Millisecond Forums

How to fully ramdomize positions of targets?

https://forums.millisecond.com/Topic16071.aspx

By AmandaChina123 - 4/19/2015

The key stimuli show in sequence: stimuli 1 appear, stimuli 1 disappear and stimuli 2 appear and so on.... I want to make them show in different positions, is that possible? Thanks.
By Dave - 4/19/2015

Yes. You can pull positions from e.g. a <list> element.
By AmandaChina123 - 4/19/2015

Thanks. But the list could only have the number of stimuli. For example, I have 8 stimuli, and I want them to appear on different space of the screen. Is that possible? Thank you for your patience.
By Dave - 4/19/2015

Yes, that's perfectly possible. And no, <list> elements are not confined to holding item numbers.

<trial mytrial>
/ stimulusframes = [1=a,b,c,d]
/ validresponse = (57)
</trial>

<list hpos>
/ items = (40%, 60%, 40%, 60%)
/ selectionrate = always
</list>

<list vpos>
/ items = (35%, 35%, 65%, 65%)
/ selectionmode = list.hpos.currentindex
/ selectionrate = always
</list>

<text a>
/ items = ("A")
/ hposition = list.hpos.nextvalue
/ vposition = list.vpos.nextvalue
</text>

<text b>
/ items = ("B")
/ hposition = list.hpos.nextvalue
/ vposition = list.vpos.nextvalue
</text>

<text c>
/ items = ("C")
/ hposition = list.hpos.nextvalue
/ vposition = list.vpos.nextvalue
</text>

<text d>
/ items = ("D")
/ hposition = list.hpos.nextvalue
/ vposition = list.vpos.nextvalue
</text>

By AmandaChina123 - 4/19/2015

Thank you very much! But for some reason it doesn't work, I think I must be wrong in some step.

<item shapes>
/ 1 = "1.gif"
/ 2 = "2.gif"
/ 3 = "3.gif"
/ 4 = "4.gif"
/ 5 = "5.gif"
/ 6 = "6.gif"
/ 7 = "7.gif"
/ 8 = "8.gif"
</item>

*list.notargetvalue selects any of the 8 numbers (item indices) but the one selected for values.currenttarget
<list notargetvalue>
/items = (1,2,3,4,5,6,7,8)
/ not = (values.currenttarget)
/ select = replace
</list>

<list hpos>
/ items = (12%, 22%, 84%, 82%, 20%, 39%, 44%, 78%)
/ selectionrate = always
</list>

<list vpos>
/ items = (37%, 51%, 60%, 25%, 41%, 71%, 76%, 70%)
/ selectionmode = list.hpos.currentindex
/ selectionrate = always
</list>

<text 1>
/ items = ("1")
/ hposition = list.hpos.nextvalue
/ vposition = list.vpos.nextvalue
</text>

<text 2>
/ items = ("2")
/ hposition = list.hpos.nextvalue
/ vposition = list.vpos.nextvalue
</text>

<text 3>
/ items = ("3")
/ hposition = list.hpos.nextvalue
/ vposition = list.vpos.nextvalue
</text>

<text 4>
/ items = ("4")
/ hposition = list.hpos.nextvalue
/ vposition = list.vpos.nextvalue
</text>

<text 5>
/ items = ("5")
/ hposition = list.hpos.nextvalue
/ vposition = list.vpos.nextvalue
</text>

<text 6>
/ items = ("6")
/ hposition = list.hpos.nextvalue
/ vposition = list.vpos.nextvalue
</text>

<text 7>
/ items = ("7")
/ hposition = list.hpos.nextvalue
/ vposition = list.vpos.nextvalue
</text>

<text 8>
/ items = ("8")
/ hposition = list.hpos.nextvalue
/ vposition = list.vpos.nextvalue
</text>

By Dave - 4/19/2015

Since that code is woefully incomplete, I cannot tell you where your mistake is.
- You didn't include the <trial> that actually displays the stimuli
- The purpose of the <item> element is unclear. It isn't used anywhere in that code.
- The same is true for <list notargetvalue>.

The *only* elements that make use of the position lists (hpos, vpos) are the eight <text> elements. Their purpose is unclear. If you are displaying images, your <picture> elements ought to make use of those lists.

If you have a <trial> actually display the eight <text> elements, you will find that the code works exactly as it should:

<trial mytrial>
/ stimulusframes = [1=1,2,3,4,5,6,7,8]
/ validresponse = (57)
</trial>

<list hpos>
/ items = (12%, 22%, 84%, 82%, 20%, 39%, 44%, 78%)
/ selectionrate = always
</list>

<list vpos>
/ items = (37%, 51%, 60%, 25%, 41%, 71%, 76%, 70%)
/ selectionmode = list.hpos.currentindex
/ selectionrate = always
</list>

<text 1>
/ items = ("1")
/ hposition = list.hpos.nextvalue
/ vposition = list.vpos.nextvalue
</text>

<text 2>
/ items = ("2")
/ hposition = list.hpos.nextvalue
/ vposition = list.vpos.nextvalue
</text>

<text 3>
/ items = ("3")
/ hposition = list.hpos.nextvalue
/ vposition = list.vpos.nextvalue
</text>

<text 4>
/ items = ("4")
/ hposition = list.hpos.nextvalue
/ vposition = list.vpos.nextvalue
</text>

<text 5>
/ items = ("5")
/ hposition = list.hpos.nextvalue
/ vposition = list.vpos.nextvalue
</text>

<text 6>
/ items = ("6")
/ hposition = list.hpos.nextvalue
/ vposition = list.vpos.nextvalue
</text>

<text 7>
/ items = ("7")
/ hposition = list.hpos.nextvalue
/ vposition = list.vpos.nextvalue
</text>

<text 8>
/ items = ("8")
/ hposition = list.hpos.nextvalue
/ vposition = list.vpos.nextvalue
</text>

https://www.millisecond.com/forums/uploads/images/0bbe8251-5476-4653-a036-4f56.png
By AmandaChina123 - 4/19/2015

May I paste the complete code here? I'm only using the practice trial in this experiment. Thanks
.
************************************************************************************************************************************************************************
************************************************************************************************************************************************************************
SINGLE N-BACK TASK ADAPTIVE (1 KEY VERSION)
************************************************************************************************************************************************************************
************************************************************************************************************************************************************************
       SCRIPT INFO

Author: Katja Borchert, Ph.D. (katjab@millisecond.com) for Millisecond Software LLC
Date: October, 2011

last updated: 09-26-2014 by K. Borchert for Millisecond Software

Copyright © 09-26-2014 Millisecond Software
************************************************************************************************************************************************************************

************************************************************************************************************************************************************************
 BACKGROUND INFO

Acknowledgements:
This script implements an adaptive version of the non-adaptive single n-back task version of the N-Back procedure as is described in the
following publication (Experiment1):
Jaeggi, Susanne M.; Studer-Luethi, Barbara; Buschkuehl, Martin; Su, Yi-Fen; Jonides, John; Perrig, Walter J. (2010). The
relationship between n-back performance and matrix reasoning - implications for training and transfer. Intelligence, 38, 625–635.

Millisecond Software thanks Dr. Susanne Jaeggi for kindly providing original instruction materials, stimuli, as well as assistance!

This Inquisit script provides trials and instructions for adaptive single n-back tasks with random shapes (N = 1, N = 2, N = 3, N = 4),
inspired by the non-adaptive version with the same stimuli used and kindly provided by Jaeggi et al (2010)- used in Experiment 1, as well
as the general procedure described for adaptive n-back testing in Experiment 2.
In this script, participants start out on level N = 1 and can move up to level N = 4. However, instructions of how to add further levels
of N are also provided.

Single n-back tasks:
In 1-key single n-back tasks, participants are shown a sequence of stimuli (here: a sequence of yellow shapes on a black background) and
asked to indicate whether the currently presented stimulus fulfills the following criteria:

for N=1 trials:
- is the shape the same as the one that preceded it? If so (it's a target), and press "A". If not, don't respond.

for N=2 trials:
- is the shape the same as the one presented two trials before? If so (it's a target), and press "A". If not, don't respond.

for N=3 trials:
- is the shape the same as the one presented three trials before? If so (it's a target), and press "A". If not, don't respond.

for N=4 trials:
- is the shape the same as the one presented four trials before? If so (it's a target), and press "A". If not, don't respond.

Specific Procedural Information
(1) Single n-back EXPERIMENT (adaptive) information:
- After instructions, participants receive 10 trials of practice for levels N = 1 to N= 3, with possibility for more
- After practice, participants start on level N = 1, and depending on performance move up or stay on that level
- Adaptive testing is over after 15 blocks

(2) Single n-back BLOCK information:
- Each single n-task block consists of 20+ trials using 8 different shapes.
=> + trials are the N trials that cannot display target shapes yet (=start trials). Their numbers vary depending on N. The data collected
during these start trials are NOT included in performance counts for Correct Rejections/False Alarms.
=> Of the actual 20 experimental trials, 6 present a target and 14 do not.
- The computer selects randomly
a) whether it is a target trial or not and
b) what shape to show if it is not a target trial
-adaptive blocks:
(a) based on performance of participants either a higher, lower or the same level N is chosen for the following block (after 15 blocks the session is over)
(b) adaptive testing starts at level N = 1 in this script
(c) participants receive performance feedback (% correct) after each block

(3) Single n-back TRIAL information:
- Each trial presents the shape for 500ms and waits another 2500ms before presenting the next shape in the sequence.
- Participants have the entire 3000ms to respond by pressing "A" if they detect a target.

************************************************************************************************************************************************************************

************************************************************************************************************************************************************************
INFORMATION FOR CODE-CHANGES (e.g. ADDITIONAL/DIFFERENT LEVELS OF N)

Instructions for changing code for additional Ns are provided with this script. Please check the following sections for the relevant info:
1. Custom Values
2. Instructions: (a) Instruction Slides (b) Instruction Blocks
3. Trials
4. Blocks: (a) Practice (b) Experimental
************************************************************************************************************************************************************************

************************************************************************************************************************************************************************
DEFAULTS

requires Inquisit 4.0.0.0

<defaults>
/minimumversion = "4.0.0.0"

/ screencolor = black
</defaults>
/canvasaspectratio = (4,3)

************************************************************************************************************************************************************************

************************************************************************************************************************************************************************
CUSTOM VALUES

*********************
editable parameters (with default values)
*********************
/StartN = 1the starting N
!Note: if the starting N changes other changes need to be made,
/LastN = 4the last N run
/LastPracticeN = 3last N tested in Practice (default is 3)
/NumberTestBlocks = 15Number of test blocks run (default is 15)
/debugmode = 0debugmode = 1: targetalerts are shown on screen, debugmode = 0, no targetalerts are shown (default)

<values>
/StartN = 1
/LastN = 4
/LastPracticeN = 3
/NumberTestBlocks = 15
/debugmode = 0
</values>

*********************
updated at runtime
*********************
minus1:contains the stimulusitemnumber of the stimulus in the trial preceding the current one
minus2:contains the stimulusitemnumber of the stimulus shown 2 trials before the current one
minus3:contains the stimulusitemnumber of the stimulus shown 3 trials before the current one
minus4:contains the stimulusitemnumber of the stimulus shown 4 trials before the current one
stim:contains the current stimulusitem
stimnumber:contains the current stimulusitemnumber
N:the lag between a target and the stimulus it repeats
currenttarget:contains the stimulusnumber of the current target
(a target in N = 0 trials is a stimulus with the same stimulus number as stored in target0)
Hits:codes the number of correctly identifiying a target
FalseA:codes the number of times a participant identifies a non-target as a target
Misses:codes the number of times a participant misses to identify a target
CorrReject:codes the number of times a participant correctly identifies a non-target (and does nothing)
values.TotalHits:the number of total hits across all experimental blocks
values.TotalFA:the number of total false alarms across all experimental blocks
values.TotalBlocks:the total number of experimental blocks run
values.DV:dependent variable (DV) in Jaeggi et al (2010): the proportion of (TotalHits - TotalFA)/number of total blocks
starttrialcounter:keeps track of how many start trials have been run
repetitioncounter:keeps track of how many times an experimental block has been run

<values >
/completed = 0
/minus1 = 0
/minus2 = 0
/minus3 = 0
/minus4 = 0
/N = 0
/currenttarget = 0
/Hits = 0
/FalseA = 0
/Misses = 0
/CorrReject = 0
/TotalHits = 0
/TotalFA = 0
/DV = 0
/TotalBlocks = 0
/starttrialcounter = 0
/repetitioncounter = 0
</values>

**************************ADDITIONAL N-LEVELS*************************************
* if additional N-levels are needed, create and add further "minusN" values and set them to 0,
Example: N = 5
/minus5 = 0

************************************************************************************************************************************************************************

************************************************************************************************************************************************************************
DATA COLLECTION

this implementation suggests to collect the following information:
date:Date of Experiment
time:Time of Day
subject:Subjectnumber
values.N:the type of N-back trial
blockcode:the name of the current block
values.TotalBlocks:the total number of experimental blocks run
trialcode:the name of the current trial
stimulusitem:the file of the stimulus shown during a trial
stimulusnumber:the item number of the stimulus shown during a trial
values.currenttarget:the item number of the current target
response:the response of the participant
correct:the correctness of the response
latency:how fast a participant responded within the 3000ms timeframe, if at all
values.Hits:the number of Hits
values.FalseA:the number of False Alarms
values. Misses:the number of Misses
values.CorrReject:the number of Correct Rejections
values.TotalHits:the number of total hits across all experimental blocks
values.TotalFA:the number of total false alarms across all experimental blocks
values.DV:the proportion of (TotalHits - TotalFA)/number of experimental blocks


**********************
raw data
**********************

<data>
/file = "SingleTaskAdaptiveNBack_rawdata.iqdat"
/columns = [date, time, subject, values.N, blockcode, values.TotalBlocks, trialcode, trialnum, stimulusitem, stimulusnumber, values.currenttarget, response, correct, latency
values.Hits, values.FalseA, values.Misses, values.CorrReject, values.TotalHits, values.TotalFA, values.DV]
/ separatefiles = true
</data>

**********************
summary data
**********************
script.startdate:date script was run
script.starttime:time script was started
script.subjectid:subject id number
script.groupid:group id number
script.elapsedtime:time it took to run script (in ms)
/completed:0 = script was not completed (script was prematurely aborted); 1 = script was completed (all conditions run)

values.TotalHits:the sum of total hits across all experimental blocks
values.TotalFA:the number of total false alarms across all experimental blocks
values.DV:the proportion of (TotalHits - TotalFA)/number of experimental blocks

<summarydata >
/file = "SingleTaskAdaptiveNBack_summary.iqdat"
/columns = [script.startdate, script.starttime, script.subjectid, script.groupid, script.elapsedtime, values.completed,
values.N, values.TotalHits, values.TotalFA, values.DV]
</summarydata>


************************************************************************************************************************************************************************

************************************************************************************************************************************************************************
INSTRUCTIONS
*******CODE CHANGES:
If you would like to run different levels of N in practice/experimental trials, change/add the necessary instruction slides
as well as pay attention to the changes necessary under "Instruction Blocks"


***********INSTRUCTION SLIDES*****************************
<item Nback_startinstructions>
/1 = "SingleNbackInstructions_start.gif"
/2 = "SingleNbackInstructions_N1.gif"
/3 = "SingleNbackInstructions_N2.gif"
/4 = "SingleNbackInstructions_N3.gif"
/5 = -> "SingleNbackInstructions_practice123.gif"
</item>

NOTE:
*the remaining items/instructions provided
->"SingleNbackInstructions_practice234.gif"
-> "SingleNbackInstructions_N4.gif"

*original slide
<item practiceend>
/1 = "SingleNbackInstructions_practiceend1234.gif"
</item>

NOTE:
If higher values of N are run, change this slide


*slides to start experimental trials/end experiment
<item startendslides>
/1 = "StartExpt.gif"
/2 = "ThankYouSlide.gif"
</item>

*Instructions for individual experimental N-levels (not original)
<item expinstructions>
/1 = "SingleNbackInstructionsN1exp.gif"
/2 = "SingleNbackInstructionsN2exp.gif"
/3 = "SingleNbackInstructionsN3exp.gif"
/4 = "SingleNbackInstructionsN4exp.gif"
</item>




***********INSTRUCTION IMAGE SELECTION******************************************
<picture SingleNbackinstructions_start>
/ items = Nback_startinstructions
/ select = sequence
/ size = (100%, 100%)
</picture>

<picture Practice_end>
/ items = practiceend
/select = 1
/ size = (100%, 100%)
</picture>

<picture StartExp_slide>
/ items = startendslides
/ select = 1
/ size = (100%, 100%)
</picture>

<picture EndExp_slide>
/ items = startendslides
/select = 2
/ size = (100%, 100%)
</picture>

*instructions for individual experimental trials are selected depending on level of N
<picture expinstructionslide>
/items = expinstructions
/select = values.N
/size = (100%, 100%)
</picture>

<picture repeatpractice_page>
/items = ("SingleNbackInstructions_practicerepeat.gif")
/size = (100%, 100%)
</picture>

***********INSTRUCTION TRIALS*******************************************
<trial Nbackinstruct_starttrial>
/ stimulusframes = [1 = SingleNbackinstructions_start]
/ validresponse = (57)
/ recorddata = false
</trial>

<trial Practice_endtrial>
/ stimulusframes = [1 = Practice_end]
/ validresponse = (57)
/ recorddata = false
</trial>

<trial StartExp_trial>
/ stimulusframes = [1 = StartExp_slide]
/ validresponse = (57)
/ recorddata = false
</trial>

<trial expinstructiontrial>
/ stimulusframes = [1 = expinstructionslide]
/ validresponse = (57)
/ recorddata = false
</trial>

*only for practice trials:
<trial practice_expinstructiontrial>
/ stimulusframes = [1 = expinstructionslide]
/ validresponse = (57)
/ recorddata = false
/ errormessage = false
/ correctmessage = false
</trial>

<trial repeatpractice>
/ stimulusframes = [1 = repeatpractice_page]
/ validresponse = (49, 21)
/ recorddata = false
</trial>

*****stores TotalHits, TotalFA, and DV into datafile
<trial EndExp_trial>
/ stimulusframes = [1 = EndExp_slide]
/ validresponse = (57)
/ recorddata = false
</trial>

*************INSTRUCTION BLOCKS*************************************************************************************

ATTENTION: PRACTICE BLOCKS - code changes
(1) This block sets the beginning N value for practice trials (here: values.N = values.StartN)
(2) runs original instructions 1-5, for N=1-3, if more/fewer than three N examples are given adjust /trials = [1-X.....]
<block Nbackinstruct_start>
/ trials = [1-5 = Nbackinstruct_starttrial]
/ recorddata = false
/ onblockbegin = [values.N = values.StartN]
</block>

<block RepeatPractice>
/trials = [1 = repeatpractice]
/ recorddata = false
/ branch = [
if (trial.repeatpractice.response == 21) {values.N = 1; block.practice_s_ntask} else block.Practiceblock_end;
]
/ screencolor = (0,0,0)
</block>


<block Practiceblock_end>
/ trials = [1 = Practice_endtrial]
/ recorddata = false
</block>

ATTENTION: EXPERIMENTAL BLOCKS
(1) This block sets the starting value of N (here: values.N = values.StartN)
<block StartExp>
/ trials = [1 = StartExp_trial]
/ recorddata = false
/ onblockbegin = [
values.N = values.StartN;
values.TotalHits = 0;
values.TotalFA = 0;
values.TotalBlocks = 0;
values.DV = 0
]
</block>

<block EndExp>
/ trials = [1 = EndExp_trial]
</block>


************************************************************************************************************************************************************************

************************************************************************************************************************************************************************
SUMMARY PAGES

*A feedback page that could be presented at the end of each experimental block
(NOT included in the NON-ADAPTIVE version, but is included in the ADAPTIVE version)

<instruct >
/ fontstyle = ("Arial", 2.67%, false, false, false, false, 5, 0)
/ txcolor = (255, 255, 255)
/ screencolor = (0, 0, 0)
/ windowsize = (70%, 60%)
</instruct>


<page BlockSummary>
^^               FEEDBACK
^^
^^CORRECT: <% ((values.Hits + values.CorrReject) /20) * 100 %>% of the times
</page>

<page BlockSummary_practice>
^^               FEEDBACK
^^
^^CORRECT: <% ((values.Hits + values.CorrReject) /10) * 100 %>% of the times
</page>

************************************************************************************************************************************************************************

************************************************************************************************************************************************************************
SHAPES
*yellow on black background
*original shapes, kindly provided by Jaeggi et al (2010)

<item shapes>
/ 1 = "1.gif"
/ 2 = "2.gif"
/ 3 = "3.gif"
/ 4 = "4.gif"
/ 5 = "5.gif"
/ 6 = "6.gif"
/ 7 = "7.gif"
/ 8 = "8.gif"
</item>
************************************************************************************************************************************************************************

************************************************************************************************************************************************************************
STIMULI-SELECTION

****list Variables to select notargetvalue

*list.notargetvalue selects any of the 8 numbers (item indices) but the one selected for values.currenttarget
<list notargetvalue>
/items = (1, 2, 3, 4, 5, 6, 7, 8)
/ not = (values.currenttarget)
/ select = replace
</list>

<list hpos>
/ items = (12%, 22%, 84%, 82%, 20%, 39%, 44%, 78%)
/ selectionrate = always
</list>

<list vpos>
/ items = (37%, 51%, 60%, 25%, 41%, 71%, 76%, 70%)
/ selectionmode = list.hpos.currentindex
/ selectionrate = always
</list>

<text a>
/ items = ("1")
/ hposition = list.hpos.nextvalue
/ vposition = list.vpos.nextvalue
</text>

<text b>
/ items = ("2")
/ hposition = list.hpos.nextvalue
/ vposition = list.vpos.nextvalue
</text>

<text c>
/ items = ("3")
/ hposition = list.hpos.nextvalue
/ vposition = list.vpos.nextvalue
</text>

<text d>
/ items = ("4")
/ hposition = list.hpos.nextvalue
/ vposition = list.vpos.nextvalue
</text>

<text e>
/ items = ("5")
/ hposition = list.hpos.nextvalue
/ vposition = list.vpos.nextvalue
</text>

<text f>
/ items = ("6")
/ hposition = list.hpos.nextvalue
/ vposition = list.vpos.nextvalue
</text>

<text g>
/ items = ("7")
/ hposition = list.hpos.nextvalue
/ vposition = list.vpos.nextvalue
</text>

<text h>
/ items = ("8")
/ hposition = list.hpos.nextvalue
/ vposition = list.vpos.nextvalue
</text>


***randomly selects one of the shapes
<picture startshape>
/ items = shapes
/select = replace
/size = (40%, 40%)
</picture>

***selects any shape but the established target
<picture nontargetshape>
/ items = shapes
/ select = notargetvalue
/size = (40%, 40%)
</picture>

***selects the item with the same item number as the established target
<picture targetshape>
/items = shapes
/select = values.currenttarget
/size = (40%, 40%)
</picture>

************************************************************************************************************************************************************************

************************************************************************************************************************************************************************
FEEDBACK MESSAGES FOR PRACTICE TRIALS ONLY
<text ErrorFeedback>
/ items = ("ERROR")
/ fontstyle = ("Arial", 5.00%, true, false, false, false, 5, 0)
/ txcolor = (255, 0, 0)
/ txbgcolor = (0, 0, 0)
/ position = (50%, 70%)
</text>

<text CorrectFeedback>
/ items = ("CORRECT")
/ fontstyle = ("Arial", 5.00%, true, false, false, false, 5, 0)
/ txcolor = (0, 255, 0)
/ txbgcolor = (0, 0, 0)
/ position = (50%, 70%)
</text>

************************************************************************************************************************************************************************

************************************************************************************************************************************************************************
ASSISTANT STIMULI

*****acts as an eraser after showing the key stimuli for 500ms, staying on for the remainder of the 3000ms dedicated to each trial
<shape eraser>
/ shape = rectangle
/ size = (100%, 100%)
/ color = (0, 0, 0)
</shape>

*****Debug Code:
<text targetalert>
/items = ("target")
/position = (50%, 80%)
/txcolor = (black)
/txbgcolor = (black)
/ fontstyle = ("Arial", 3%, true, false, false, false, 5, 1)
</text>
************************************************************************************************************************************************************************

************************************************************************************************************************************************************************
TRIALS
*there are 3 types of trials
1. start: presented at beginning of block when number of trials too small for Target trials; they can present
any of the stimuli (N = 0, start trial presents the target shape)
2. nontarget:trials that present stimuli that do not repeat the stimulus of n-trials before
3. target:trials that present Target stimuli



*start trial runs N-times (unless N = 0, then it runs N = 1 time)
<trial start>
/ stimulustimes = [0 = startshape; 500 = eraser]
/ validresponse = (noresponse, 30)
/ correctresponse = (noresponse)
/ ontrialbegin = [
{if (values.N == 1) values.currenttarget = values.minus1};
{if (values.N == 2) values.currenttarget = values.minus2};
{if (values.N == 3) values.currenttarget = values.minus3};
{if (values.N == 4) values.currenttarget = values.minus4};
values.starttrialcounter += 1;
]
/ ontrialend = [
{if (values.N == 0) values.currenttarget = picture.startshape.currentitemnumber};
values.minus4 = values.minus3;
values.minus3 = values.minus2;
values.minus2 = values.minus1;
values.minus1 = picture.startshape.currentitemnumber
]
/ responsetime = 0
/trialduration = 3000
/branch = [if (values.starttrialcounter < values.N) trial.start]
</trial>


<trial nontarget>
/ stimulustimes = [0 = nontargetshape; 500 = eraser]
/validresponse = (noresponse, 30)
/ correctresponse = (noresponse)
/ ontrialbegin = [
{if (values.N == 1) values.currenttarget = values.minus1};
{if (values.N == 2) values.currenttarget = values.minus2};
{if (values.N == 3) values.currenttarget = values.minus3};
{if (values.N == 4) values.currenttarget = values.minus4}
]
/ ontrialend = [
values.minus4 = values.minus3;
values.minus3 = values.minus2;
values.minus2 = values.minus1;
values.minus1 = picture.nontargetshape.currentitemnumber;
values.CorrReject = values.CorrReject + trial.nontarget.correct;
values.FalseA = values.FalseA + trial.nontarget.error;
values.TotalFA = values.TotalFA + trial.nontarget.error;
values.DV = (values.TotalHits - values.TotalFA)/values.TotalBlocks;

]
/ responsetime = 0
/ trialduration = 3000
</trial>


**if target, press the letter "A" (code: 30)
<trial target>
/ stimulustimes = [0 = targetshape, targetalert; 500 = eraser]
/validresponse = (noresponse, 30)
/ correctresponse = (30)
/ ontrialbegin = [
{if (values.N == 1) values.currenttarget = values.minus1};
{if (values.N == 2) values.currenttarget = values.minus2};
{if (values.N == 3) values.currenttarget = values.minus3};
{if (values.N == 4) values.currenttarget = values.minus4};
]
/ ontrialend = [
values.minus4 = values.minus3;
values.minus3 = values.minus2;
values.minus2 = values.minus1;
values.minus1 = picture.targetshape.currentitemnumber;
values.Hits = values.Hits+ trial.target.correct;
values.Misses = values.Misses + trial.target.error;
values.TotalHits = values.TotalHits + trial.target.correct;
values.DV = (values.TotalHits - values.TotalFA)/values.TotalBlocks;
]
/ responsetime = 0
/ trialduration = 3000
</trial>

********************************ADDITIONAL N-LEVELS*****************************************************

For each trial type:
(1) add {if (values.N == X) values.currenttarget = values.minusX};, e.g. N = 5
/ ontrialbegin = [
.....
{if (values.N == 1) values.currenttarget = values.minus1};
{if (values.N == 2) values.currenttarget = values.minus2};
{if (values.N == 3) values.currenttarget = values.minus3};
{if (values.N == 4) values.currenttarget = values.minus4};
=>{if (values.N == 5) values.currenttarget = values.minus5};
]
(2) add values.minusX = values.minus(X-1) e.g. N = 5 - largest N goes on top of the list
/ ontrialend = [
=>values.minus5 = values.minus4;
values.minus4 = values.minus3;
values.minus3 = values.minus2;
values.minus2 = values.minus1;
values.minus1 = picture.targetshape.currentitemnumber;
....
]

************************************************************************************************************************************************************************

************************************************************************************************************************************************************************
PRACTICE-BLOCKS-NONADAPTIVE


* Practice Blocks do NOT record data
* Block starts with (a) Instructiontrial (b) N start-trials that cannot present Targets yet (no data collected) (c) 10 practice trials
* 10 practice trials: ratio targets : nontargets = 3 : 7

<block practice_s_ntask>
/ onblockbegin = [
values.currenttarget = 0; values.minus1 = 0; values.minus2 = 0; values.minus3 = 0; values.minus4 = 0;
values.TotalBlocks += 1;
values.starttrialcounter = 0;
values.repetitioncounter += 1;
values.Hits = 0; values.FalseA = 0; values.Misses = 0; values.CorrReject = 0;
]
/ trials = [1 = practice_expinstructiontrial; 2 = start; 3 - 12 = noreplace(nontarget, nontarget, nontarget, nontarget, nontarget, nontarget, nontarget,
target, target, target)]
/ onblockend = [values.TotalHits = 0; values.TotalFA = 0; values.DV = 0]
/ screencolor = (0, 0, 0)
/ recorddata = true
/ postinstructions = (BlockSummary_practice)
/ branch = [if (values.N == values.LastPracticeN && values.repetitioncounter == 1) {values.TotalBlocks = 0; values.repetitioncounter = 0; block.RepeatPractice}]
/ branch = [if (values.repetitioncounter < 1) block.practice_s_ntask else { values.N += 1; values.repetitioncounter = 0; block.practice_s_ntask}]
</block>

if trial feedback is desired:
/ errormessage = true(ErrorFeedback, 500)
/ correctmessage = true(CorrectFeedback, 500)

************************************** ADDITIONAL N-LEVELS********************************************************
(1) add values.minusX = 0 to
/ onblockbegin = [
values.currenttarget = 0; values.minus1 = 0; values.minus2 = 0; values.minus3 = 0; values.minus4 = 0;
.....
]

Example: N = 5
/ onblockbegin = [
values.currenttarget = 0; values.minus1 = 0; values.minus2 = 0; values.minus3 = 0; values.minus4 = 0;
values.minus5 = 0;
.....
]
************************************************************************************************************************************************************************

************************************************************************************************************************************************************************
EXPERIMENTAL-BLOCKS ADAPTIVE

*********** ADAPTIVE N-BACK EXPERIMENTAL Blocks*****************************
*if a participant makes fewer than 3 errors on a level then participant moves up a level (see Jaeggi et al (2010))
*if a participant makes more than 5 errors on a level then participant moves down a level (see Jaeggi et al (2010))
*otherwise participant stays on the same level (see Jaeggi et al (2010))
*Max number of blocks: 15 (see Jaeggi et al (2010), Experiment 2, p.630), editable parameter
*Blocks give performance feedback (see Jaeggi et al (2010), Experiment 2, p.630)
*errors defined in this script: sum of Misses and False Alarms

* Block starts with 1 instruction trial and is followed by N start-trials that cannot present targets yet (not included in performance analyses)
* in remaining 20 trials: ratio nontargets : targets: 14 : 6 = 7 : 3
<block s_ntask_adapt>
/ onblockbegin = [
values.currenttarget = 0; values.minus1 = 0; values.minus2 = 0; values.minus3 = 0; values.minus4 = 0;
values.Hits = 0; values.FalseA = 0; values.Misses = 0; values.CorrReject = 0;
values.TotalBlocks += 1; values.starttrialcounter = 0;
]
/ trials = [1 = expinstructiontrial; 2 = start; 3 - 22 = noreplace(nontarget, nontarget, nontarget, nontarget, nontarget, nontarget, nontarget,
target, target, target)]
/ screencolor = (0, 0, 0)
/ postinstructions = (BlockSummary)
/ branch = [if (values.TotalBlocks == values.NumberTestBlocks) block.EndExp]
/ branch = [if (values.N < values.LastN && ((values.Misses + values.FalseA) < 3)) {values.N += 1; block.s_ntask_adapt}]
/ branch = [if (values.N > 1 && ((values.Misses + values.FalseA) > 5)) {values.N -= 1; block.s_ntask_adapt}
else block.s_ntask_adapt]
</block>

****************************************ADDITIONAL N-LEVELS/CODE ALTERATIONS********************************************************
(1) add values.minusX = 0 to
/ onblockbegin = [
values.currenttarget = 0; values.minus1 = 0; values.minus2 = 0; values.minus3 = 0; values.minus4 = 0;
.....
]

Example: N = 5
/ onblockbegin = [
values.currenttarget = 0; values.minus1 = 0; values.minus2 = 0; values.minus3 = 0; values.minus4 = 0;
values.minus5 = 0;
.....
]

************************************************************************************************************************************************************************

************************************************************************************************************************************************************************
EXPERIMENT

*After running the initial instructions, participants work through practice blocks for N = 1 to N = 3
* After practice, participants work through
15 blocks of levels N = 1 to N = 4 (depending on performance)


<expt>
/onexptbegin = [if (values.debugmode == 1) text.targetalert.textcolor = (red)]
/ blocks = [
1 = Nbackinstruct_start;
2 = practice_s_ntask;
]
/onexptend = [values.completed = 1]
</expt>

************************************************************************************************************************************************************************
End of Script
************************************************************************************************************************************************************************

By Dave - 4/19/2015

(1) Please don't paste entire scripts into a post. If you must, attach the actual script *file* to your post. Use the +Insert menu to upload files.
(2) No trial in your script actually displays any stimuli that would make use of the position lists. All you did is add the <list>s and a bunch of <text> elements to it. They are not used. The elements whose position you want to vary ought to make use of those lists.
E.g.

<picture nontargetshape>
/ items = shapes
/ select = notargetvalue
/size = (40%, 40%)
/ hposition = list.hpos.nextvalue
/ vposition = list.vpos.nextvalue

</picture>
By AmandaChina123 - 4/19/2015

Sorry for that. I will try to contact someone to delete the whole code.

Thank you very much, I finally did it!

By Dave - 4/19/2015

> Sorry for that. I will try to contact someone to delete the whole code.

No worries, you can leave it as it is. The reasons why attaching files is preferable:
- Massive portions of code make a post hard to follow / read.
- Pasting code into the editor may introduce mistakes not present in the actual script or obscure errors present in the actual script. Attaching the actual file ensures that others are seeing exactly what you are seeing.
- It makes the code very hard to examine and work with (you have to select it all, copy it, paste it into Inquisit Lab, etc.).
By AmandaChina123 - 4/19/2015

Thank you very much for your prompt reply.
Would you mind helping me with one more question?
Since the practice trials have three levels, I want to change the show time of each level. For example, for N=1, show time is 500ms, for N=2, show time is 1000ms and 2000ms for N=3. I was wondering that I need to define more trials, right?
Thank you very much again!
By Dave - 4/19/2015

No, you don't necessarily need to define additional <trial> elements. You can change

<trial nontarget>
/ stimulustimes = [0 = nontargetshape; 500 = eraser]
...
</trial>

to

<trial nontarget>
/ ontrialbegin = [if (values.N==1) trial.nontarget.insertstimulustime(shape.eraser, 500)]
/ ontrialbegin = [if (values.N==2) trial.nontarget.insertstimulustime(shape.eraser, 1000)]
/ ontrialbegin = [if (values.N==3) trial.nontarget.insertstimulustime(shape.eraser, 2000)]
/ ontrialend = [trial.nontarget.resetstimulusframes()]
/ stimulustimes = [0 = nontargetshape]
...
</trial>

to achieve different display durations depending on the N-level. (Do the same for the target trials.)
By AmandaChina123 - 4/19/2015

Thank you very much! But the trialduration is always the same. I just want it to be 500ms, 1000ms or 2000ms. However, if I delete the trialduration, it doesn't run at all....

*start trial runs N-times (unless N = 0, then it runs N = 1 time)
<trial start>
/ ontrialbegin = [if (values.N==1) trial.start.insertstimulustime(shape.eraser, 500)]
/ ontrialbegin = [if (values.N==2) trial.start.insertstimulustime(shape.eraser, 1000)]
/ ontrialbegin = [if (values.N==3) trial.start.insertstimulustime(shape.eraser, 2000)]
/ ontrialend = [trial.start.resetstimulusframes()]
/ stimulustimes = [0 = startshape]
/ validresponse = (noresponse, 30)
/ correctresponse = (noresponse)
/ ontrialbegin = [
{if (values.N == 1) values.currenttarget = values.minus1};
{if (values.N == 2) values.currenttarget = values.minus2};
{if (values.N == 3) values.currenttarget = values.minus3};
{if (values.N == 4) values.currenttarget = values.minus4};
values.starttrialcounter += 1;
]
/ ontrialend = [
{if (values.N == 0) values.currenttarget = picture.startshape.currentitemnumber};
values.minus4 = values.minus3;
values.minus3 = values.minus2;
values.minus2 = values.minus1;
values.minus1 = picture.startshape.currentitemnumber
]
/ responsetime = 0
/trialduration = 3000
/branch = [if (values.starttrialcounter < values.N) trial.start]
</trial>


<trial nontarget>
/ ontrialbegin = [if (values.N==1) trial.nontarget.insertstimulustime(shape.eraser, 500)]
/ ontrialbegin = [if (values.N==2) trial.nontarget.insertstimulustime(shape.eraser, 1000)]
/ ontrialbegin = [if (values.N==3) trial.nontarget.insertstimulustime(shape.eraser, 2000)]
/ ontrialend = [trial.nontarget.resetstimulusframes()]
/ stimulustimes = [0 = nontargetshape]
/validresponse = (noresponse, 30)
/ correctresponse = (noresponse)
/ ontrialbegin = [
{if (values.N == 1) values.currenttarget = values.minus1};
{if (values.N == 2) values.currenttarget = values.minus2};
{if (values.N == 3) values.currenttarget = values.minus3};
{if (values.N == 4) values.currenttarget = values.minus4}
]
/ ontrialend = [
values.minus4 = values.minus3;
values.minus3 = values.minus2;
values.minus2 = values.minus1;
values.minus1 = picture.nontargetshape.currentitemnumber;
values.CorrReject = values.CorrReject + trial.nontarget.correct;
values.FalseA = values.FalseA + trial.nontarget.error;
values.TotalFA = values.TotalFA + trial.nontarget.error;
values.DV = (values.TotalHits - values.TotalFA)/values.TotalBlocks;

]
/ responsetime = 0
/ trialduration = 3000
</trial>


**if target, press the letter "A" (code: 30)
<trial target>
/ ontrialbegin = [if (values.N==1) trial.target.insertstimulustime(shape.eraser, 500)]
/ ontrialbegin = [if (values.N==2) trial.target.insertstimulustime(shape.eraser, 1000)]
/ ontrialbegin = [if (values.N==3) trial.target.insertstimulustime(shape.eraser, 2000)]
/ ontrialend = [trial.target.resetstimulusframes()]
/ stimulustimes = [0 = targetshape]
/validresponse = (noresponse, 30)
/ correctresponse = (30)
/ ontrialbegin = [
{if (values.N == 1) values.currenttarget = values.minus1};
{if (values.N == 2) values.currenttarget = values.minus2};
{if (values.N == 3) values.currenttarget = values.minus3};
{if (values.N == 4) values.currenttarget = values.minus4};
]
/ ontrialend = [
values.minus4 = values.minus3;
values.minus3 = values.minus2;
values.minus2 = values.minus1;
values.minus1 = picture.targetshape.currentitemnumber;
values.Hits = values.Hits+ trial.target.correct;
values.Misses = values.Misses + trial.target.error;
values.TotalHits = values.TotalHits + trial.target.correct;
values.DV = (values.TotalHits - values.TotalFA)/values.TotalBlocks;
]
/ responsetime = 0
/ trialduration = 3000

By Dave - 4/19/2015

You need to distinguish between two different things:

#1 is the display duration of the target or non-target stimulus. In the original that's hardcoded to 500ms:

<trial nontarget>
/ stimulustimes = [0 = nontargetshape; 500 = eraser]
...
</trial>

nontargetshape is displayed at t0 and is overwritten by <shape eraser> 500ms later.

#2 is the <trial> element's *overall* duration, which is *unrelated* to #1 above and fixed at 3000ms in the original:

<trial nontarget>
...
/trialduration = 3000
</trial>

If you want to vary that depending on the N-level, you need to introduce a new <values> entry

<values>
...
/ mytrialduration = 500
...
</values>

and set values.mytrialduration to the desired value depending on N-level:

<trial nontarget>
/ ontrialbegin = [if (values.N==1) values.mytrialduration = 500]
/ ontrialbegin = [if (values.N==2) values.mytrialduration = 1000]
/ ontrialbegin = [if (values.N==3) values.mytrialduration = 2000]
...
/ trialduration = values.mytrialduration
...
</trial>
By AmandaChina123 - 4/19/2015

Thank you very much for your kind help! I solved all my problems now.

Thank you! Have a good night!
By Dave - 4/19/2015

Have a nice evening, too!
By AmandaChina123 - 4/19/2015

Hello, I just got new questions.... 
I'm trying to use different key stimuli under different durations (500ms, 1000ms, 2000ms), do you know how to define N=1,2,3 to stand for different key stimuli? For example, under N=1 and duration=500ms, the key stimuli are some numbers; Under N=2 and duration=1000ms, the key stimuli are simple equations; Under N=3 and duration=2000ms, the key stimuli are complex equations.
Thank you very much!
By Dave - 4/19/2015

Then you need to set up e.g. three <list>s, each representing the items applicable to the N-level.

Suppose you have

<item shapes>
/ 1 = "N1_1.gif"
/ 2 = "N1_2.gif"
/ 3 = "N1_3.gif"

/ 4 = "N2_1.gif"
/ 5 = "N2_2.gif"
/ 6 = "N2_3.gif"

/ 7 = "N3_1.gif"
/ 8 = "N3_2.gif"
/ 9 = "N3_3.gif"
</item>

i.e., three items per N-level (1-3 for N=1; 4-6 for N=2; 7-9 for N=3). Then you need

<list n1notargetlist>
/ items = (1,2,3)
/ not = (values.currenttarget)
/ select = replace
</list>

<list n2notargetlist>
/ items = (4,5,6)
/ not = (values.currenttarget)
/ select = replace
</list>

<list n3notargetlist>
/ items = (7,8,9)
/ not = (values.currenttarget)
/ select = replace
</list>

with

<values>
...
/ notargetitem = 1
...
</values>

<picture nontargetshape>
/ items = shapes
/ select = values.notargetitem
...
</picture>

and

<trial nontarget>
/ ontrialbegin = [if (values.N==1) {values.mytrialduration = 500; values.notargetitem=list.n1notargetlist.nextvalue}]
/ ontrialbegin = [if (values.N==2) values.mytrialduration = 1000; values.notargetitem=list.n2notargetlist.nextvalue}]
/ ontrialbegin = [if (values.N==3) values.mytrialduration = 2000; values.notargetitem=list.n2notargetlist.nextvalue}]
...
/ trialduration = values.mytrialduration
...
</trial>

You need to adapt the target-logic analogously.

Finally, I would *strongly* recommend you first work through the original / unchanged script until you sufficiently understand how it works (pay attention to the comments throughout). That will make it easier for you to adapt it to your needs / modify it.