Millisecond Forums

Counting clicks on stimulus during trial

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

By 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>



By 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>