Reply To: Randomization of presentation of columns in trial with last column always last

PennController for IBEX › Forums › Support › Randomization of presentation of columns in trial with last column always last › Reply To: Randomization of presentation of columns in trial with last column always last

#7759
Jeremy
Keymaster

Hi,

You can reference the keys set1, set2, set3 and set4 in an array and shuffle it using Ibex’s fisherYates:

Template("speecherrors.csv", row =>
    newTrial("repetition",
        defaultText
            .css("p")
            .center()
            .print()
        ,
        newText("Please repeat the following sets of words as fast as you can when they appear on the screen. Press start to display them.")
            .css("p")
        ,
        newButton("Start")
            .log()
            .center()
            .print()
            .wait()
            .remove()
        ,
        newTimer("wait", 1000)
            .log()
            .start()
            .wait()
        ,
        newMediaRecorder("speech_set1", "audio")
            .log()
            .record()
        ,
        newText( "blank line" )
            .hidden()
        ,
        row.sets = ["set1","set2","set3","set4"],  // array of keys
        fisherYates(row.sets)                      // shuffle the array
        ,
        newText("set1", row[row.sets[0]])          // use the first (shuffled) key
            .log()
        ,
        newTimer("wait", 3000)
            .log()
            .callback(getMediaRecorder("speech_set1").stop())
            .start()
            .wait()
        ,
        getText("set1")
            .remove()
        ,
        newTimer("wait", 1000)
            .log()
            .start()
            .wait()
        ,
        newMediaRecorder("speech_set2", "audio")
            .log()
            .record()
        ,
        newText("set2", row[row.sets[1]])          // use the second (shuffled) key
            .log()
        ,
        newTimer("wait", 3000)
            .log()
            .callback(getMediaRecorder("speech_set2").stop())
            .start()
            .wait()
        ,
        getText("set2")
            .remove()
        ,
        newTimer("wait", 1000)
            .log()
            .start()
            .wait()
        ,
        newMediaRecorder("speech_set3", "audio")
            .log()
            .record()
        ,
        newText("set3", row[row.sets[2]])          // use the third (shuffled) key
            .log()
        ,
        newTimer("wait", 3000)
            .log()
            .callback(getMediaRecorder("speech_set3").stop())
            .start()
            .wait()
        ,
        getText("set3")
            .remove()
        ,
        newTimer("wait", 1000)
            .log()
            .start()
            .wait()
        ,
        newMediaRecorder("speech_set4", "audio")
            .log()
            .record()
        ,
        newText("set4", row[row.sets[3]])          // use the fourth (shuffled) key
            .log()
        ,
        newTimer("wait", 3000)
            .log()
            .callback(getMediaRecorder("speech_set4").stop())
            .start()
            .wait()
        ,
        getText("set4")
            .remove()
        ,
        newTimer("wait", 1000)
            .log()
            .start()
            .wait()
        ,
        newMediaRecorder("speech_target", "audio")
            .log()
            .record()
        ,
        newText("target", row.target)
            .log()
        ,
        newTimer("wait", 3000)
            .log()
            .callback(getMediaRecorder("speech_target").stop())
            .start()
            .wait()
        ,
        getText("target")
            .remove()
    )
    .log("first", row[row.sets[0]])   // log the first shuffled key
    .log("second", row[row.sets[1]])  // log the second shuffled key
    .log("third", row[row.sets[2]])   // log the third shuffled key
    .log("fourth", row[row.sets[3]])  // log the fourth shuffled key
    .log("target", row.target)        // log the target word too
)

Jeremy