Reply To: Trial judgement and present unequal fillers

PennController for IBEX Forums Support Trial judgement and present unequal fillers Reply To: Trial judgement and present unequal fillers

#9737
xkyan
Participant

Hi Jeremy,

Thanks for the previous answers! Here’s a follow-up:

I tried to reorganize my materials and correct my codes as following. But the Sequence controller did not work (my guess) so I can’t present trials in the order I want.


PennController.ResetPrefix(null)
// DebugOff()

// function ----------------------------------
const nRandomIntsToSum = (length,minInt,maxInt,targetSum) => {
    const a = [];
    for (let i=0; i<length; i++) {
      let min = minInt, max = maxInt, remainder = targetSum-(a.reduce((x,y)=>x+y,0)+min*(length-(i+1)));
      if (remainder < maxInt) max = remainder;
      a.push( min+Math.round(Math.random()*(max-min)) );
    }
    fisherYates(a);
    return a;
}

const pic = row => [
    // set a fixation
    newText("fixation1", "+")
        .css("font-size","50px")
        .print("center at 50%" , "center at 50%")
        .log()
    ,
    newTimer("fixtime1",500).start().wait()
    ,
    getText("fixation1").remove() 
    ,
    // set the picture stimuli
    newImage("pic", row.flan_file).size(720, 405).print()
    ,
    newCanvas("canvas_pic",720,405)
        .add( 0, 0, getImage("pic"))
        .center().print()
    ,
    // start recording RT
    getVar("RT1").global().set( v => Date.now() )
    ,
    // set key response
    newKey("flan_RespKey", "FJ")
        .log("flan_RespKey", getKey("flan_RespKey"))
        .wait()
        .callback(
            getVar("RT1").set( v => Date.now() - v )
                .log( "flanRT" , getVar("RT1") )
        )
    ,
    // record RT
    getVar("RT1").set( v => Date.now() - v )
        .log( "flanRT" , getVar("RT1") )
    ,
    // clear the screen
    getCanvas("canvas_pic").remove()
];

const spr = row => [
    // set a fixation
    newText("fixation2", "+")
        .css("font-size","50px")
        .print("center at 50%" , "center at 50%")
        .log()
    ,
    newTimer("fixtime2",500).start().wait()
    ,
    getText("fixation2").remove() 
    ,
    // set the spr stimuli
    newController("DashedSentence", {s: row.sent_cont})
        .print()
        .log()
        .wait()
        .remove()
    ,
    // start recording RT
    getVar("RT2").global().set( v => Date.now() )
    ,
    newController("Question", {q: "这句话合理吗?", as: [["F","合理"], ["J","不合理"]], hasCorrect: parseInt(row.sentCorr), randomOrder: false})
        .print()
        .log()
        .wait()
        .remove()
    ,
    // record RT
    getVar("RT2").set( v => Date.now() - v )
        .log( "sentRT" , getVar("RT2") )
];

// Main --------------------------

  
// Instructions
newTrial("instructions",
    defaultText
        .cssContainer({"margin-bottom":"1em"})
        .center()
        .print()
    ,
    newText("instructions-1", "Welcome!")
    ,
    newText("instructions-2", "In this experiment, you will hear and read a sentence, and see two images.")
    ,
    newText("instructions-3", "<b>Select the image that better matches the sentence:</b>")
    ,
    newText("instructions-4", "Press the <b>F</b> key to select the image on the left.<br>Press the <b>J</b> key to select the image on the right.<br>You can also click on an image to select it.")
    ,
    newTextInput("input_ID")
        .cssContainer({"margin-bottom":"1em"})
        .center()
        .print()
    ,
    newButton("wait", "Click to start the experiment")
        .center()
        .print()
        .wait()
    ,
    newVar("ID")
        .global()
        .set(getTextInput("input_ID"))
)

// Define the template for target trials (完成,没问题)
Template("items-targets.csv", row =>
    newTrial("targets",
        newVar("RT1").global().set("0"),
        newVar("RT2").global().set("0"),

        pic(row)
        ,
        spr(row)
    )
)

// Define the template for filler trials
Template("items-fillers-flan.csv", row =>
    newTrial("fillers",
        pic(row)
    )
)
Template("items-fillers-spr.csv", row =>
    newTrial("fillers",
        spr(row)
    )
)

targets = randomize("targets")
fillers = randomize("fillers")
repetitions = nRandomIntsToSum(60,1,3,120)

Sequence(
    "instructions",
    repetitions.map(n=>[ pick(targets,1),pick(fillers,n) ]).flat()
  )

// Sequence("instructions", randomize("targets"))
// Sequence("instructions", "targets")

However, I found that when I ran it, it would go over with the Template order I coded (i.e. all targets in the sequential order as in the csv file, then the filler-flan, then the filler-spr) and the Sequence controller seems not work at all. Here are some other observations I hope to share with you while attempting to debug:

1. I tried to change the order of Template and the presented order during experiment changed correspondingly, which proved that the Sequence controller indeed did not work and it went with the order of the Template. It makes sense after checking the doc because I found that the function of Template is generating trials so the trials are presented once they are generated.
2. I tried to change the Sequence to see which part of Sequence can work. For example, I tried Sequence("instructions", "fillers", randomize("targets")) and it worked! So I guess there might be something wrong with my current Sequence design so it failed to work and therefore the experiment just went with the sequential order of Templates. But after checking .map and .flat, I still didn’t find where the bug is in this line.

Could you please help me figure out why it fails? I’ve been stuck here for quite a long time which is frustrating 🙁 I really appreciate your help! Thanks in advance.