Millisecond Forums

If/then with scan codes

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

By troyh - 1/27/2021

Hello,
I'm trying to set up a study, where there are 3 pictures on the screen at once and participants use key presses to select the pictures, e.g. H is Pic1, J is Pic2, and K is Pic3. The next trial depends on which picture they select, though I may be totally incompetent because I cannot seem to create a branch for scan codes, i.e. 
   [ if(trial.trial1.response == 35) trial.nexttrial] .
There is no error in my message list but Inquisit seems to just ignore it because the script ends without branching. Is there a way to create such a conditional with scan codes?
By Dave - 1/27/2021

troyh - 1/27/2021
Hello,
I'm trying to set up a study, where there are 3 pictures on the screen at once and participants use key presses to select the pictures, e.g. H is Pic1, J is Pic2, and K is Pic3. The next trial depends on which picture they select, though I may be totally incompetent because I cannot seem to create a branch for scan codes, i.e. 
   [ if(trial.trial1.response == 35) trial.nexttrial] .
There is no error in my message list but Inquisit seems to just ignore it because the script ends without branching. Is there a way to create such a conditional with scan codes?

<block myblock>
/ trials = [1-6 = example]
</block>

<trial example>
/ stimulustimes = [1=instr]
/ validresponse = ("H", "J", "K")
/ branch = [
    if (trial.example.response == 35) {
        trial.h_trial;
    } else if (trial.example.response == 36) {
        trial.j_trial;
    } else if (trial.example.response == 37) {
        trial.k_trial;
    }
]
</trial>

<text instr>
/ items = ("Press H, J, or K.")
</text>

<trial h_trial>
/ stimulusframes = [1=h_text]
/ validresponse = (57)
</trial>

<trial j_trial>
/ stimulusframes = [1=j_text]
/ validresponse = (57)
</trial>

<trial k_trial>
/ stimulusframes = [1=k_text]
/ validresponse = (57)
</trial>

<text h_text>
/ items = ("You pressed H. Press SPACE.")
</text>

<text j_text>
/ items = ("You pressed J. Press SPACE.")
</text>

<text k_text>
/ items = ("You pressed K. Press SPACE.")
</text>


works perfectly fine for me? Note that for a branch to be executed the trial with the branch needs to be run by a block -- there has to be that overarching control structure.


By troyh - 1/27/2021

Ah! Thank you so much--I did not know about the overarching control structure. It works!
By troyh - 1/27/2021

If the trial branches, is it possible to keep on screen the selected picture, along with the new trial? I'm struggling with the use of scan codes for this. The bolded part in the attached script portion is what I am envisioning..

<picture tocas>
/items = item.tocas
/position = (50%,30%)
/size = (45%,45%)
/select = sequence
</picture>

<picture cake1>
/items = item.cakes1of3
/position = (25%,62%)
/size = (20%,20%)
/select = sequence
</picture>

<picture cake2>
/items = item.cakes2of3
/position = (50%,62%)
/size = (20%,20%)
/select = sequence
</picture>

<picture cake3>
/items = item.cakes3of3
/position = (75%,62%)
/size = (20%,20%)
/select = sequence
</picture>

<picture ants>
/items = item.anticipations
/position = (30%,50%)
/size = (45%,45%)
/select = sequence
</picture>

<trial anticipation>
/stimulusframes = [
    1=ants
]
/ trialduration = 2000
</trial>

<trial mytrial>
/stimulusframes = [
    1=tocas,cake1,cake2,cake3,H,J,K
]
/validresponse = (35, 36, 37)
/branch = [
    if(trial.mytrial.response == 35){
        trial.anticipation + last selected stim from cake1;
    } else if (trial.mytrial.response == 36){
        trial.anticipation + last selected stim from cake2;
    } else if (trial.mytrial.response == 37){
        trial.anticipation +  last selected stim from cake3;
    }
]
</trial>


<block myblock>
/trials = [
    1-5=mytrial
]
</block>
By Dave - 1/27/2021

troyh - 1/28/2021
If the trial branches, is it possible to keep on screen the selected picture, along with the new trial? I'm struggling with the use of scan codes for this. The bolded part in the attached script portion is what I am envisioning..

<picture tocas>
/items = item.tocas
/position = (50%,30%)
/size = (45%,45%)
/select = sequence
</picture>

<picture cake1>
/items = item.cakes1of3
/position = (25%,62%)
/size = (20%,20%)
/select = sequence
</picture>

<picture cake2>
/items = item.cakes2of3
/position = (50%,62%)
/size = (20%,20%)
/select = sequence
</picture>

<picture cake3>
/items = item.cakes3of3
/position = (75%,62%)
/size = (20%,20%)
/select = sequence
</picture>

<picture ants>
/items = item.anticipations
/position = (30%,50%)
/size = (45%,45%)
/select = sequence
</picture>

<trial anticipation>
/stimulusframes = [
    1=ants
]
/ trialduration = 2000
</trial>

<trial mytrial>
/stimulusframes = [
    1=tocas,cake1,cake2,cake3,H,J,K
]
/validresponse = (35, 36, 37)
/branch = [
    if(trial.mytrial.response == 35){
        trial.anticipation + last selected stim from cake1;
    } else if (trial.mytrial.response == 36){
        trial.anticipation + last selected stim from cake2;
    } else if (trial.mytrial.response == 37){
        trial.anticipation +  last selected stim from cake3;
    }
]
</trial>


<block myblock>
/trials = [
    1-5=mytrial
]
</block>

When you need to provide code, please

(1) Provide code that is complete, i.e. that actually runs.
(2) Provide any external files the code requires to run.

Put it in a ZIP and attach it to your post via +Insert -> Add File.

Thank you!
By troyh - 1/27/2021

sorry about that! 
It does not seem to be small enough to attach. There are many pictures
By Dave - 1/27/2021

troyh - 1/28/2021
sorry about that! 
It does not seem to be small enough to attach. There are many pictures

Then strip down the script to only use, idk, 20 items. I don't need the full script with hundreds of images, just something that (1) runs and (2) is a fair representation of the actual task.
By troyh - 1/28/2021

I am terribly sorry--I could not even get the zip to upload but for some reason each stim uploaded fine on their own. I hope this is ok-- if not, I appreciate your help!
By Dave - 1/28/2021

troyh - 1/28/2021
I am terribly sorry--I could not even get the zip to upload but for some reason each stim uploaded fine on their own. I hope this is ok-- if not, I appreciate your help!

<item tocas>
/1 = "FinalVersionToca1_nomouth.jpg"



</item>
<item cakes1of3>
/1 = "Cake1.jpg"


</item>
<item cakes2of3>
/1 = "Cake31.jpg"



</item>
<item cakes3of3>
/1 = "Cake61.jpg"



</item>
<item outcomes>
/1 = "FinalVersionToca1_neutral.jpg"



</item>
<item anticipations>
/1 = "FinalVersionToca1_anticipation.jpg"



</item>

<text H>
/items = ("H")
/position = (25%, 85%)
/size = (20%,20%)
</text>
<text J>
/items = ("J")
/position = (50%,85%)
/size = (20%,20%)
</text>
<text K>
/items = ("K")
/position = (75%,85%)
/size = (20%,20%)
</text>

<picture tocas>
/items = item.tocas
/position = (50%,30%)
/size = (45%,45%)
/select = sequence
</picture>

<picture cake1>
/items = item.cakes1of3
/position = (25%,62%)
/size = (20%,20%)
/select = sequence
</picture>

<picture cake2>
/items = item.cakes2of3
/position = (50%,62%)
/size = (20%,20%)
/select = sequence
</picture>

<picture cake3>
/items = item.cakes3of3
/position = (75%,62%)
/size = (20%,20%)
/select = sequence
</picture>

<picture ants>
/items = item.anticipations
/position = (30%,50%)
/size = (45%,45%)
/select = sequence
</picture>

// cake1.jpg merely serves as placeholder item
// it will be replace with the image of the selected cake
// at runtime.
<picture cakepic>
/ items = ("cake1.jpg")
/position = (50%,62%)
/size = (20%,20%)
</picture>

<trial anticipation>
/stimulusframes = [
  1=ants, cakepic
]
/ trialduration = 2000
</trial>

<trial mytrial>
/stimulusframes = [
  1=tocas,cake1,cake2,cake3,H,J,K
]
/validresponse = (35, 36, 37)
/branch = [
  if(trial.mytrial.response == 35){
        picture.cakepic.setitem(picture.cake1.currentitem, 1);
   trial.anticipation;
  } else if (trial.mytrial.response == 36){
        picture.cakepic.setitem(picture.cake2.currentitem, 1);
   trial.anticipation;
  } else if (trial.mytrial.response == 37){
        picture.cakepic.setitem(picture.cake3.currentitem, 1);
   trial.anticipation;
  }
]
</trial>

<block cb1>
/trials = [
    1-3=mytrial
]
</block>

By troyh - 1/28/2021

Perfect! Thanks, Dave! You're a lifesaver