Counting clicks on stimulus during trial


Author
Message
Amelinq
Amelinq
Associate Member (293 reputation)Associate Member (293 reputation)Associate Member (293 reputation)Associate Member (293 reputation)Associate Member (293 reputation)Associate Member (293 reputation)Associate Member (293 reputation)Associate Member (293 reputation)Associate Member (293 reputation)
Group: Forum Members
Posts: 23, Visits: 65
Hi all,
For an experiment (pavlovian-instrumental-transfer task) I'm programming a task with 3 phases: first a very simple classical conditioning phase in which participants learn that a stimulus (apple) gets followed by a movieclip, and another stimulus (banana) gets followed by nothing. secondly an instrumental learning phase in which they click on a butterfly to get a movieclip. In a third phase, I want to present the butterfly along with either the banana or the apple for 10 seconds per trial. During these trials in the third phase, I want to count the clicks on the butterfly (without having seperate trials per click, because then the stimuli "flash" ). I expect there to be more clicks on the butterfly when accompanied by the apple compared to the banana.

How can I code this click-counting and save it in the data?

thanks a lot! I put the code underneath.
Amelie

// DEFAULTS
<defaults>
/ screencolor = white
/ txbgcolor = white
/ txcolor = black
/ halign = center
/ vAlign = center
/ fontstyle = ("Arial", 3%)
</defaults>

//PINGU VIDEO's

<video v1>
/items = ("01.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v2>
/items = ("02.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v3>
/items = ("03.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v4>
/items = ("04.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v5>
/items = ("05.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v6>
/items = ("06.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v7>
/items = ("07.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v8>
/items = ("08.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v9>
/items = ("09.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v10>
/items = ("10.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v11>
/items = ("11.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v12>
/items = ("12.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v13>
/items = ("13.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v14>
/items = ("14.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v15>
/items = ("15.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v16>
/items = ("16.mp4")
/ playThrough = false
/ position = (50,50)
/ size = (70%,70%)
</video>
<video v17>
/items = ("17.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v18>
/items = ("18.mp4")
/ playThrough = true
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>


// make list of video's

<list videos>
/items = (video.v1, video.v2,video.v3,video.v4,video.v5,video.v6,video.v7,video.v8,video.v9,video.v10,video.v11,video.v12,video.v13,video.v14,video.v15,video.v16, video.v17,video.v18)
/selectionmode= random
/maxrunsize= 1
/replace = false
</list>

// PICTURES
<picture apple>
/items = ("s2.jpg")
/ position = (50%, 30%)
/ size = (40%, 40%)
</picture>

<picture banana>
/items = ("s1.jpg")
/ position = (50%, 30%)
/ size = (40%, 40%)
</picture>

<picture butterfly>
/items = ("response.jpg")
/ position = (50%, 80%)
/ size = (40%, 40%)
</picture>

<picture star>
/items = ("Star.jpg")
/ position = (10%, 90%)
/ size = (20%, 20%)
</picture>

<picture blank>
/items = ("blank.png")
/ position = (50%, 50%)
/ size = (200%, 200%)
</picture>
<sound chimes >
/items =("chimes.wav")
/playthrough = true
</sound>
<sound notify >
/items =("notify.wav")
/playthrough = true
</sound>
<picture blackbox>
/items = ("blackbox.png")
/ position = (20%,20%)
</picture>


// TRIALS
<trial appletrial>
/stimulustimes = [0= blank; 2000 = apple,chimes; 6000= list.videos]
/validresponse = (noresponse)
/timeout = 18000
</trial>

<trial bananatrial>
/stimulustimes = [0= blank; 2000 = banana,notify; 6000 = blank]
/validresponse = (noresponse)
/timeout = 18000
</trial>
<trial blank>
/stimulustimes = [0 = blank]
/ timeout = 2000
</trial>

<trial videofeedback>
/stimulustimes = [0= star; 1000= list.videos]
/validresponse = (noresponse)
/timeout = 11000
</trial>

<trial butterflytrial1>
/stimulustimes = [1 = butterfly]
/inputdevice = mouse
/correctresponse = (butterfly)
/responseinterrupt = trial
/branch = {
  if (trial.butterflytrial1.correct) {
   return trial.videofeedback;
  }
}

</trial>

<trial butterflytrial2>
/ stimulustimes = [1= butterfly]
/ inputdevice = mouse
/ correctResponse = (butterfly)
/branch= {
    if (trial.butterflytrial2.correct == true) {
   return trial.butterflytrial1;
  }
}
/ responseinterrupt = trial
</trial>

<trial butterflytrial3>
/ stimulustimes = [1= butterfly]
/ inputdevice = mouse
/ correctResponse = (butterfly)
/branch= {
    if (trial.butterflytrial3.correct == true) {
   return trial.butterflytrial2;
  }
}
/ responseinterrupt = trial
</trial>

<trial butterflytrial4>
/ stimulustimes = [1= butterfly]
/ inputdevice = mouse
/ correctResponse = (butterfly)
/branch= {
    if (trial.butterflytrial4.correct == true) {
   return trial.butterflytrial3;
  }
}
/ responseinterrupt = trial
</trial>


//blocks
<block pav1>
/trials = [1 = trial.appletrial; 2 =trial.bananatrial]
</block>
<block pav2>
/trials = [1 = trial.bananatrial; 2 =trial.appletrial]
</block>

<block instrumental>
/ trials = [1 = trial.butterflytrial1; 2= butterflytrial2; 3-10 = random(butterflytrial1, butterflytrial2,butterflytrial3,butterflytrial4)]
</block>


<expt pit>
/ blocks = [1-6= noReplaceNoRepeat(pav1, pav1, pav1, pav2, pav2, pav2); 7= instrumental]
</expt>




Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 13K, Visits: 109K
Amelinq - 4/15/2025
Hi all,
For an experiment (pavlovian-instrumental-transfer task) I'm programming a task with 3 phases: first a very simple classical conditioning phase in which participants learn that a stimulus (apple) gets followed by a movieclip, and another stimulus (banana) gets followed by nothing. secondly an instrumental learning phase in which they click on a butterfly to get a movieclip. In a third phase, I want to present the butterfly along with either the banana or the apple for 10 seconds per trial. During these trials in the third phase, I want to count the clicks on the butterfly (without having seperate trials per click, because then the stimuli "flash" ). I expect there to be more clicks on the butterfly when accompanied by the apple compared to the banana.

How can I code this click-counting and save it in the data?

thanks a lot! I put the code underneath.
Amelie

// DEFAULTS
<defaults>
/ screencolor = white
/ txbgcolor = white
/ txcolor = black
/ halign = center
/ vAlign = center
/ fontstyle = ("Arial", 3%)
</defaults>

//PINGU VIDEO's

<video v1>
/items = ("01.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v2>
/items = ("02.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v3>
/items = ("03.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v4>
/items = ("04.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v5>
/items = ("05.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v6>
/items = ("06.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v7>
/items = ("07.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v8>
/items = ("08.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v9>
/items = ("09.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v10>
/items = ("10.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v11>
/items = ("11.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v12>
/items = ("12.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v13>
/items = ("13.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v14>
/items = ("14.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v15>
/items = ("15.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v16>
/items = ("16.mp4")
/ playThrough = false
/ position = (50,50)
/ size = (70%,70%)
</video>
<video v17>
/items = ("17.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v18>
/items = ("18.mp4")
/ playThrough = true
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>


// make list of video's

<list videos>
/items = (video.v1, video.v2,video.v3,video.v4,video.v5,video.v6,video.v7,video.v8,video.v9,video.v10,video.v11,video.v12,video.v13,video.v14,video.v15,video.v16, video.v17,video.v18)
/selectionmode= random
/maxrunsize= 1
/replace = false
</list>

// PICTURES
<picture apple>
/items = ("s2.jpg")
/ position = (50%, 30%)
/ size = (40%, 40%)
</picture>

<picture banana>
/items = ("s1.jpg")
/ position = (50%, 30%)
/ size = (40%, 40%)
</picture>

<picture butterfly>
/items = ("response.jpg")
/ position = (50%, 80%)
/ size = (40%, 40%)
</picture>

<picture star>
/items = ("Star.jpg")
/ position = (10%, 90%)
/ size = (20%, 20%)
</picture>

<picture blank>
/items = ("blank.png")
/ position = (50%, 50%)
/ size = (200%, 200%)
</picture>
<sound chimes >
/items =("chimes.wav")
/playthrough = true
</sound>
<sound notify >
/items =("notify.wav")
/playthrough = true
</sound>
<picture blackbox>
/items = ("blackbox.png")
/ position = (20%,20%)
</picture>


// TRIALS
<trial appletrial>
/stimulustimes = [0= blank; 2000 = apple,chimes; 6000= list.videos]
/validresponse = (noresponse)
/timeout = 18000
</trial>

<trial bananatrial>
/stimulustimes = [0= blank; 2000 = banana,notify; 6000 = blank]
/validresponse = (noresponse)
/timeout = 18000
</trial>
<trial blank>
/stimulustimes = [0 = blank]
/ timeout = 2000
</trial>

<trial videofeedback>
/stimulustimes = [0= star; 1000= list.videos]
/validresponse = (noresponse)
/timeout = 11000
</trial>

<trial butterflytrial1>
/stimulustimes = [1 = butterfly]
/inputdevice = mouse
/correctresponse = (butterfly)
/responseinterrupt = trial
/branch = {
  if (trial.butterflytrial1.correct) {
   return trial.videofeedback;
  }
}

</trial>

<trial butterflytrial2>
/ stimulustimes = [1= butterfly]
/ inputdevice = mouse
/ correctResponse = (butterfly)
/branch= {
    if (trial.butterflytrial2.correct == true) {
   return trial.butterflytrial1;
  }
}
/ responseinterrupt = trial
</trial>

<trial butterflytrial3>
/ stimulustimes = [1= butterfly]
/ inputdevice = mouse
/ correctResponse = (butterfly)
/branch= {
    if (trial.butterflytrial3.correct == true) {
   return trial.butterflytrial2;
  }
}
/ responseinterrupt = trial
</trial>

<trial butterflytrial4>
/ stimulustimes = [1= butterfly]
/ inputdevice = mouse
/ correctResponse = (butterfly)
/branch= {
    if (trial.butterflytrial4.correct == true) {
   return trial.butterflytrial3;
  }
}
/ responseinterrupt = trial
</trial>


//blocks
<block pav1>
/trials = [1 = trial.appletrial; 2 =trial.bananatrial]
</block>
<block pav2>
/trials = [1 = trial.bananatrial; 2 =trial.appletrial]
</block>

<block instrumental>
/ trials = [1 = trial.butterflytrial1; 2= butterflytrial2; 3-10 = random(butterflytrial1, butterflytrial2,butterflytrial3,butterflytrial4)]
</block>


<expt pit>
/ blocks = [1-6= noReplaceNoRepeat(pav1, pav1, pav1, pav2, pav2, pav2); 7= instrumental]
</expt>




Stimuli don't "flash" (i.e. get erased at the end of a trial) when you set /erase = false in the respective stimulus elements. Have a trial that collects a single click, loop that trial for 10 seconds, count up the clicks /onTrialEnd.

<values>
/ clickCount = 0
/ timeLeft = 0
</values>

<block exampleBlock>
/ trials = [1-4=startTrial]
</block>

<trial startTrial>
/ onTrialBegin = {
    values.clickCount = 0;
    values.timeLeft = 10000;
}
/ stimulusTimes = [0=clearScreen]
/ validResponse = (0)
/ trialDuration = 500
/ branch = {
    return trial.clickTrial;
}
/ recordData = false
</trial>

<trial clickTrial>
/ onTrialEnd = {
    if (this.response == "clickMe") {
        values.clickCount++;
    };
    values.timeLeft -= this.elapsedTime;
}
/ stimulusTimes = [0=clearScreen, clickMe, clickCount]
/ inputDevice = mouse
/ validResponse = (clickMe, 0)
/ timeout = values.timeLeft
/ branch = {
    if (values.timeLeft > 0) {
        return this;
    } else {
        return trial.logData;
    }
}
/ recordData = false
</trial>

<trial logData>
/ trialDuration = 0
</trial>

<shape clickMe>
/ shape = roundedrectangle
/ color = blue
/ borderColor = azure
/ size = (10%, 10%)
/ erase = false
</shape>

<text clickCount>
/ items = ("Clicks counted: <%values.clickCount%>
\n Time left: <%values.timeLeft%>")
/ erase = false
/ position = (50%, 10%)
</text>

<data>
/ columns = (date, time, subject, group, session, blockNum, blockCode, trialNum, trialCode, response, latency, correct, values.clickCount)
</data>

Edited 7 Months Ago by Dave
Amelinq
Amelinq
Associate Member (293 reputation)Associate Member (293 reputation)Associate Member (293 reputation)Associate Member (293 reputation)Associate Member (293 reputation)Associate Member (293 reputation)Associate Member (293 reputation)Associate Member (293 reputation)Associate Member (293 reputation)
Group: Forum Members
Posts: 23, Visits: 65
Dave - 4/15/2025
Amelinq - 4/15/2025
Hi all,
For an experiment (pavlovian-instrumental-transfer task) I'm programming a task with 3 phases: first a very simple classical conditioning phase in which participants learn that a stimulus (apple) gets followed by a movieclip, and another stimulus (banana) gets followed by nothing. secondly an instrumental learning phase in which they click on a butterfly to get a movieclip. In a third phase, I want to present the butterfly along with either the banana or the apple for 10 seconds per trial. During these trials in the third phase, I want to count the clicks on the butterfly (without having seperate trials per click, because then the stimuli "flash" ). I expect there to be more clicks on the butterfly when accompanied by the apple compared to the banana.

How can I code this click-counting and save it in the data?

thanks a lot! I put the code underneath.
Amelie

// DEFAULTS
<defaults>
/ screencolor = white
/ txbgcolor = white
/ txcolor = black
/ halign = center
/ vAlign = center
/ fontstyle = ("Arial", 3%)
</defaults>

//PINGU VIDEO's

<video v1>
/items = ("01.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v2>
/items = ("02.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v3>
/items = ("03.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v4>
/items = ("04.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v5>
/items = ("05.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v6>
/items = ("06.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v7>
/items = ("07.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v8>
/items = ("08.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v9>
/items = ("09.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v10>
/items = ("10.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v11>
/items = ("11.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v12>
/items = ("12.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v13>
/items = ("13.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v14>
/items = ("14.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v15>
/items = ("15.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v16>
/items = ("16.mp4")
/ playThrough = false
/ position = (50,50)
/ size = (70%,70%)
</video>
<video v17>
/items = ("17.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v18>
/items = ("18.mp4")
/ playThrough = true
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>


// make list of video's

<list videos>
/items = (video.v1, video.v2,video.v3,video.v4,video.v5,video.v6,video.v7,video.v8,video.v9,video.v10,video.v11,video.v12,video.v13,video.v14,video.v15,video.v16, video.v17,video.v18)
/selectionmode= random
/maxrunsize= 1
/replace = false
</list>

// PICTURES
<picture apple>
/items = ("s2.jpg")
/ position = (50%, 30%)
/ size = (40%, 40%)
</picture>

<picture banana>
/items = ("s1.jpg")
/ position = (50%, 30%)
/ size = (40%, 40%)
</picture>

<picture butterfly>
/items = ("response.jpg")
/ position = (50%, 80%)
/ size = (40%, 40%)
</picture>

<picture star>
/items = ("Star.jpg")
/ position = (10%, 90%)
/ size = (20%, 20%)
</picture>

<picture blank>
/items = ("blank.png")
/ position = (50%, 50%)
/ size = (200%, 200%)
</picture>
<sound chimes >
/items =("chimes.wav")
/playthrough = true
</sound>
<sound notify >
/items =("notify.wav")
/playthrough = true
</sound>
<picture blackbox>
/items = ("blackbox.png")
/ position = (20%,20%)
</picture>


// TRIALS
<trial appletrial>
/stimulustimes = [0= blank; 2000 = apple,chimes; 6000= list.videos]
/validresponse = (noresponse)
/timeout = 18000
</trial>

<trial bananatrial>
/stimulustimes = [0= blank; 2000 = banana,notify; 6000 = blank]
/validresponse = (noresponse)
/timeout = 18000
</trial>
<trial blank>
/stimulustimes = [0 = blank]
/ timeout = 2000
</trial>

<trial videofeedback>
/stimulustimes = [0= star; 1000= list.videos]
/validresponse = (noresponse)
/timeout = 11000
</trial>

<trial butterflytrial1>
/stimulustimes = [1 = butterfly]
/inputdevice = mouse
/correctresponse = (butterfly)
/responseinterrupt = trial
/branch = {
  if (trial.butterflytrial1.correct) {
   return trial.videofeedback;
  }
}

</trial>

<trial butterflytrial2>
/ stimulustimes = [1= butterfly]
/ inputdevice = mouse
/ correctResponse = (butterfly)
/branch= {
    if (trial.butterflytrial2.correct == true) {
   return trial.butterflytrial1;
  }
}
/ responseinterrupt = trial
</trial>

<trial butterflytrial3>
/ stimulustimes = [1= butterfly]
/ inputdevice = mouse
/ correctResponse = (butterfly)
/branch= {
    if (trial.butterflytrial3.correct == true) {
   return trial.butterflytrial2;
  }
}
/ responseinterrupt = trial
</trial>

<trial butterflytrial4>
/ stimulustimes = [1= butterfly]
/ inputdevice = mouse
/ correctResponse = (butterfly)
/branch= {
    if (trial.butterflytrial4.correct == true) {
   return trial.butterflytrial3;
  }
}
/ responseinterrupt = trial
</trial>


//blocks
<block pav1>
/trials = [1 = trial.appletrial; 2 =trial.bananatrial]
</block>
<block pav2>
/trials = [1 = trial.bananatrial; 2 =trial.appletrial]
</block>

<block instrumental>
/ trials = [1 = trial.butterflytrial1; 2= butterflytrial2; 3-10 = random(butterflytrial1, butterflytrial2,butterflytrial3,butterflytrial4)]
</block>


<expt pit>
/ blocks = [1-6= noReplaceNoRepeat(pav1, pav1, pav1, pav2, pav2, pav2); 7= instrumental]
</expt>




Stimuli don't "flash" (i.e. get erased at the end of a trial) when you set /erase = false in the respective stimulus elements. Have a trial that collects a single click, loop that trial for 10 seconds, count up the clicks /onTrialEnd.

<values>
/ clickCount = 0
/ timeLeft = 0
</values>

<block exampleBlock>
/ trials = [1-4=startTrial]
</block>

<trial startTrial>
/ onTrialBegin = {
    values.clickCount = 0;
    values.timeLeft = 10000;
}
/ stimulusTimes = [0=clearScreen]
/ validResponse = (0)
/ trialDuration = 500
/ branch = {
    return trial.clickTrial;
}
/ recordData = false
</trial>

<trial clickTrial>
/ onTrialEnd = {
    if (this.response == "clickMe") {
        values.clickCount++;
    };
    values.timeLeft -= this.elapsedTime;
}
/ stimulusTimes = [0=clearScreen, clickMe, clickCount]
/ inputDevice = mouse
/ validResponse = (clickMe, 0)
/ timeout = values.timeLeft
/ branch = {
    if (values.timeLeft > 0) {
        return this;
    } else {
        return trial.logData;
    }
}
/ recordData = false
</trial>

<trial logData>
/ trialDuration = 0
</trial>

<shape clickMe>
/ shape = roundedrectangle
/ color = blue
/ borderColor = azure
/ size = (10%, 10%)
/ erase = false
</shape>

<text clickCount>
/ items = ("Clicks counted: <%values.clickCount%>
\n Time left: <%values.timeLeft%>")
/ erase = false
/ position = (50%, 10%)
</text>

<data>
/ columns = (date, time, subject, group, session, blockNum, blockCode, trialNum, trialCode, response, latency, correct, values.clickCount)
</data>

Thank you very much!

Amelinq
Amelinq
Associate Member (293 reputation)Associate Member (293 reputation)Associate Member (293 reputation)Associate Member (293 reputation)Associate Member (293 reputation)Associate Member (293 reputation)Associate Member (293 reputation)Associate Member (293 reputation)Associate Member (293 reputation)
Group: Forum Members
Posts: 23, Visits: 65
Dave - 4/15/2025
Amelinq - 4/15/2025
Hi all,
For an experiment (pavlovian-instrumental-transfer task) I'm programming a task with 3 phases: first a very simple classical conditioning phase in which participants learn that a stimulus (apple) gets followed by a movieclip, and another stimulus (banana) gets followed by nothing. secondly an instrumental learning phase in which they click on a butterfly to get a movieclip. In a third phase, I want to present the butterfly along with either the banana or the apple for 10 seconds per trial. During these trials in the third phase, I want to count the clicks on the butterfly (without having seperate trials per click, because then the stimuli "flash" ). I expect there to be more clicks on the butterfly when accompanied by the apple compared to the banana.

How can I code this click-counting and save it in the data?

thanks a lot! I put the code underneath.
Amelie

// DEFAULTS
<defaults>
/ screencolor = white
/ txbgcolor = white
/ txcolor = black
/ halign = center
/ vAlign = center
/ fontstyle = ("Arial", 3%)
</defaults>

//PINGU VIDEO's

<video v1>
/items = ("01.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v2>
/items = ("02.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v3>
/items = ("03.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v4>
/items = ("04.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v5>
/items = ("05.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v6>
/items = ("06.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v7>
/items = ("07.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v8>
/items = ("08.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v9>
/items = ("09.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v10>
/items = ("10.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v11>
/items = ("11.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v12>
/items = ("12.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v13>
/items = ("13.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v14>
/items = ("14.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v15>
/items = ("15.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v16>
/items = ("16.mp4")
/ playThrough = false
/ position = (50,50)
/ size = (70%,70%)
</video>
<video v17>
/items = ("17.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v18>
/items = ("18.mp4")
/ playThrough = true
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>


// make list of video's

<list videos>
/items = (video.v1, video.v2,video.v3,video.v4,video.v5,video.v6,video.v7,video.v8,video.v9,video.v10,video.v11,video.v12,video.v13,video.v14,video.v15,video.v16, video.v17,video.v18)
/selectionmode= random
/maxrunsize= 1
/replace = false
</list>

// PICTURES
<picture apple>
/items = ("s2.jpg")
/ position = (50%, 30%)
/ size = (40%, 40%)
</picture>

<picture banana>
/items = ("s1.jpg")
/ position = (50%, 30%)
/ size = (40%, 40%)
</picture>

<picture butterfly>
/items = ("response.jpg")
/ position = (50%, 80%)
/ size = (40%, 40%)
</picture>

<picture star>
/items = ("Star.jpg")
/ position = (10%, 90%)
/ size = (20%, 20%)
</picture>

<picture blank>
/items = ("blank.png")
/ position = (50%, 50%)
/ size = (200%, 200%)
</picture>
<sound chimes >
/items =("chimes.wav")
/playthrough = true
</sound>
<sound notify >
/items =("notify.wav")
/playthrough = true
</sound>
<picture blackbox>
/items = ("blackbox.png")
/ position = (20%,20%)
</picture>


// TRIALS
<trial appletrial>
/stimulustimes = [0= blank; 2000 = apple,chimes; 6000= list.videos]
/validresponse = (noresponse)
/timeout = 18000
</trial>

<trial bananatrial>
/stimulustimes = [0= blank; 2000 = banana,notify; 6000 = blank]
/validresponse = (noresponse)
/timeout = 18000
</trial>
<trial blank>
/stimulustimes = [0 = blank]
/ timeout = 2000
</trial>

<trial videofeedback>
/stimulustimes = [0= star; 1000= list.videos]
/validresponse = (noresponse)
/timeout = 11000
</trial>

<trial butterflytrial1>
/stimulustimes = [1 = butterfly]
/inputdevice = mouse
/correctresponse = (butterfly)
/responseinterrupt = trial
/branch = {
  if (trial.butterflytrial1.correct) {
   return trial.videofeedback;
  }
}

</trial>

<trial butterflytrial2>
/ stimulustimes = [1= butterfly]
/ inputdevice = mouse
/ correctResponse = (butterfly)
/branch= {
    if (trial.butterflytrial2.correct == true) {
   return trial.butterflytrial1;
  }
}
/ responseinterrupt = trial
</trial>

<trial butterflytrial3>
/ stimulustimes = [1= butterfly]
/ inputdevice = mouse
/ correctResponse = (butterfly)
/branch= {
    if (trial.butterflytrial3.correct == true) {
   return trial.butterflytrial2;
  }
}
/ responseinterrupt = trial
</trial>

<trial butterflytrial4>
/ stimulustimes = [1= butterfly]
/ inputdevice = mouse
/ correctResponse = (butterfly)
/branch= {
    if (trial.butterflytrial4.correct == true) {
   return trial.butterflytrial3;
  }
}
/ responseinterrupt = trial
</trial>


//blocks
<block pav1>
/trials = [1 = trial.appletrial; 2 =trial.bananatrial]
</block>
<block pav2>
/trials = [1 = trial.bananatrial; 2 =trial.appletrial]
</block>

<block instrumental>
/ trials = [1 = trial.butterflytrial1; 2= butterflytrial2; 3-10 = random(butterflytrial1, butterflytrial2,butterflytrial3,butterflytrial4)]
</block>


<expt pit>
/ blocks = [1-6= noReplaceNoRepeat(pav1, pav1, pav1, pav2, pav2, pav2); 7= instrumental]
</expt>




Stimuli don't "flash" (i.e. get erased at the end of a trial) when you set /erase = false in the respective stimulus elements. Have a trial that collects a single click, loop that trial for 10 seconds, count up the clicks /onTrialEnd.

<values>
/ clickCount = 0
/ timeLeft = 0
</values>

<block exampleBlock>
/ trials = [1-4=startTrial]
</block>

<trial startTrial>
/ onTrialBegin = {
    values.clickCount = 0;
    values.timeLeft = 10000;
}
/ stimulusTimes = [0=clearScreen]
/ validResponse = (0)
/ trialDuration = 500
/ branch = {
    return trial.clickTrial;
}
/ recordData = false
</trial>

<trial clickTrial>
/ onTrialEnd = {
    if (this.response == "clickMe") {
        values.clickCount++;
    };
    values.timeLeft -= this.elapsedTime;
}
/ stimulusTimes = [0=clearScreen, clickMe, clickCount]
/ inputDevice = mouse
/ validResponse = (clickMe, 0)
/ timeout = values.timeLeft
/ branch = {
    if (values.timeLeft > 0) {
        return this;
    } else {
        return trial.logData;
    }
}
/ recordData = false
</trial>

<trial logData>
/ trialDuration = 0
</trial>

<shape clickMe>
/ shape = roundedrectangle
/ color = blue
/ borderColor = azure
/ size = (10%, 10%)
/ erase = false
</shape>

<text clickCount>
/ items = ("Clicks counted: <%values.clickCount%>
\n Time left: <%values.timeLeft%>")
/ erase = false
/ position = (50%, 10%)
</text>

<data>
/ columns = (date, time, subject, group, session, blockNum, blockCode, trialNum, trialCode, response, latency, correct, values.clickCount)
</data>

Hi Dave,
We are now in a phase of the study in which we think it would be convenient to provide timing for each click on the stimulus (within this trial).
For each startTrial loop (in your example above), where I count and log clicks using clickTrial, I need a way to identify each individual click in the dataset along with its timestamp. In other words, I need one row per click, including the time of that click, with the timestamp resetting to 0 at the start of every loop. I can than sum up the number of clicks (rows) within this trial myself, so it is no longer needed to sum up the number of clicks in the log trial per se (but it can stay as well, if that would be possible or not make the script too complex).
Is there a chance you could help me with that?

thank you very much!
kind regards

Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 13K, Visits: 109K
Amelinq - 11/25/2025
Dave - 4/15/2025
Amelinq - 4/15/2025
Hi all,
For an experiment (pavlovian-instrumental-transfer task) I'm programming a task with 3 phases: first a very simple classical conditioning phase in which participants learn that a stimulus (apple) gets followed by a movieclip, and another stimulus (banana) gets followed by nothing. secondly an instrumental learning phase in which they click on a butterfly to get a movieclip. In a third phase, I want to present the butterfly along with either the banana or the apple for 10 seconds per trial. During these trials in the third phase, I want to count the clicks on the butterfly (without having seperate trials per click, because then the stimuli "flash" ). I expect there to be more clicks on the butterfly when accompanied by the apple compared to the banana.

How can I code this click-counting and save it in the data?

thanks a lot! I put the code underneath.
Amelie

// DEFAULTS
<defaults>
/ screencolor = white
/ txbgcolor = white
/ txcolor = black
/ halign = center
/ vAlign = center
/ fontstyle = ("Arial", 3%)
</defaults>

//PINGU VIDEO's

<video v1>
/items = ("01.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v2>
/items = ("02.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v3>
/items = ("03.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v4>
/items = ("04.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v5>
/items = ("05.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v6>
/items = ("06.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v7>
/items = ("07.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v8>
/items = ("08.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v9>
/items = ("09.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v10>
/items = ("10.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v11>
/items = ("11.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v12>
/items = ("12.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v13>
/items = ("13.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v14>
/items = ("14.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v15>
/items = ("15.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v16>
/items = ("16.mp4")
/ playThrough = false
/ position = (50,50)
/ size = (70%,70%)
</video>
<video v17>
/items = ("17.mp4")
/ playThrough = false
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>
<video v18>
/items = ("18.mp4")
/ playThrough = true
/ position = (50,50)
/ erase = true
/ size = (70%,70%)
</video>


// make list of video's

<list videos>
/items = (video.v1, video.v2,video.v3,video.v4,video.v5,video.v6,video.v7,video.v8,video.v9,video.v10,video.v11,video.v12,video.v13,video.v14,video.v15,video.v16, video.v17,video.v18)
/selectionmode= random
/maxrunsize= 1
/replace = false
</list>

// PICTURES
<picture apple>
/items = ("s2.jpg")
/ position = (50%, 30%)
/ size = (40%, 40%)
</picture>

<picture banana>
/items = ("s1.jpg")
/ position = (50%, 30%)
/ size = (40%, 40%)
</picture>

<picture butterfly>
/items = ("response.jpg")
/ position = (50%, 80%)
/ size = (40%, 40%)
</picture>

<picture star>
/items = ("Star.jpg")
/ position = (10%, 90%)
/ size = (20%, 20%)
</picture>

<picture blank>
/items = ("blank.png")
/ position = (50%, 50%)
/ size = (200%, 200%)
</picture>
<sound chimes >
/items =("chimes.wav")
/playthrough = true
</sound>
<sound notify >
/items =("notify.wav")
/playthrough = true
</sound>
<picture blackbox>
/items = ("blackbox.png")
/ position = (20%,20%)
</picture>


// TRIALS
<trial appletrial>
/stimulustimes = [0= blank; 2000 = apple,chimes; 6000= list.videos]
/validresponse = (noresponse)
/timeout = 18000
</trial>

<trial bananatrial>
/stimulustimes = [0= blank; 2000 = banana,notify; 6000 = blank]
/validresponse = (noresponse)
/timeout = 18000
</trial>
<trial blank>
/stimulustimes = [0 = blank]
/ timeout = 2000
</trial>

<trial videofeedback>
/stimulustimes = [0= star; 1000= list.videos]
/validresponse = (noresponse)
/timeout = 11000
</trial>

<trial butterflytrial1>
/stimulustimes = [1 = butterfly]
/inputdevice = mouse
/correctresponse = (butterfly)
/responseinterrupt = trial
/branch = {
  if (trial.butterflytrial1.correct) {
   return trial.videofeedback;
  }
}

</trial>

<trial butterflytrial2>
/ stimulustimes = [1= butterfly]
/ inputdevice = mouse
/ correctResponse = (butterfly)
/branch= {
    if (trial.butterflytrial2.correct == true) {
   return trial.butterflytrial1;
  }
}
/ responseinterrupt = trial
</trial>

<trial butterflytrial3>
/ stimulustimes = [1= butterfly]
/ inputdevice = mouse
/ correctResponse = (butterfly)
/branch= {
    if (trial.butterflytrial3.correct == true) {
   return trial.butterflytrial2;
  }
}
/ responseinterrupt = trial
</trial>

<trial butterflytrial4>
/ stimulustimes = [1= butterfly]
/ inputdevice = mouse
/ correctResponse = (butterfly)
/branch= {
    if (trial.butterflytrial4.correct == true) {
   return trial.butterflytrial3;
  }
}
/ responseinterrupt = trial
</trial>


//blocks
<block pav1>
/trials = [1 = trial.appletrial; 2 =trial.bananatrial]
</block>
<block pav2>
/trials = [1 = trial.bananatrial; 2 =trial.appletrial]
</block>

<block instrumental>
/ trials = [1 = trial.butterflytrial1; 2= butterflytrial2; 3-10 = random(butterflytrial1, butterflytrial2,butterflytrial3,butterflytrial4)]
</block>


<expt pit>
/ blocks = [1-6= noReplaceNoRepeat(pav1, pav1, pav1, pav2, pav2, pav2); 7= instrumental]
</expt>




Stimuli don't "flash" (i.e. get erased at the end of a trial) when you set /erase = false in the respective stimulus elements. Have a trial that collects a single click, loop that trial for 10 seconds, count up the clicks /onTrialEnd.

<values>
/ clickCount = 0
/ timeLeft = 0
</values>

<block exampleBlock>
/ trials = [1-4=startTrial]
</block>

<trial startTrial>
/ onTrialBegin = {
    values.clickCount = 0;
    values.timeLeft = 10000;
}
/ stimulusTimes = [0=clearScreen]
/ validResponse = (0)
/ trialDuration = 500
/ branch = {
    return trial.clickTrial;
}
/ recordData = false
</trial>

<trial clickTrial>
/ onTrialEnd = {
    if (this.response == "clickMe") {
        values.clickCount++;
    };
    values.timeLeft -= this.elapsedTime;
}
/ stimulusTimes = [0=clearScreen, clickMe, clickCount]
/ inputDevice = mouse
/ validResponse = (clickMe, 0)
/ timeout = values.timeLeft
/ branch = {
    if (values.timeLeft > 0) {
        return this;
    } else {
        return trial.logData;
    }
}
/ recordData = false
</trial>

<trial logData>
/ trialDuration = 0
</trial>

<shape clickMe>
/ shape = roundedrectangle
/ color = blue
/ borderColor = azure
/ size = (10%, 10%)
/ erase = false
</shape>

<text clickCount>
/ items = ("Clicks counted: <%values.clickCount%>
\n Time left: <%values.timeLeft%>")
/ erase = false
/ position = (50%, 10%)
</text>

<data>
/ columns = (date, time, subject, group, session, blockNum, blockCode, trialNum, trialCode, response, latency, correct, values.clickCount)
</data>

Hi Dave,
We are now in a phase of the study in which we think it would be convenient to provide timing for each click on the stimulus (within this trial).
For each startTrial loop (in your example above), where I count and log clicks using clickTrial, I need a way to identify each individual click in the dataset along with its timestamp. In other words, I need one row per click, including the time of that click, with the timestamp resetting to 0 at the start of every loop. I can than sum up the number of clicks (rows) within this trial myself, so it is no longer needed to sum up the number of clicks in the log trial per se (but it can stay as well, if that would be possible or not make the script too complex).
Is there a chance you could help me with that?

thank you very much!
kind regards

First change /recordData = false to /recordData = true in the respeciive <trial> element.
https://www.millisecond.com/support/docs/current/html/language/attributes/recorddata.htm

It is unclear what you understand to be the timestamp (relative to what?). You may simply wish to log the script.elapsedTime property to the data file.
https://www.millisecond.com/support/docs/current/html/language/properties/elapsedtime.htm


Edited 3 days ago @ 8:25 AM by Dave
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Explore
Messages
Mentions
Search