Reply To: Randomize audios

PennController for IBEX Forums Support Randomize audios Reply To: Randomize audios

#7388
Jeremy
Keymaster

Hi,

Yes, you can use plain javascript to randomize the order of the audios. Here’s how I would go about it:

Template("training.csv", row =>
    newTrial("training",
        audios = [row.audio1,row.audio2,row.audio3].sort(v=>0.5-Math.random()),
        newTimer("break", 1000)
            .start()
            .wait()
        ,
        newImage("image1", row.image1)
            .size(200, 200)
        ,
        newImage("image2", row.image2)
            .size(200, 200)
        ,
        newImage("image3", row.image3)
            .size(200, 200)
        ,
        newCanvas("side-by-side", 700,200)
            .add(  0, 0, getImage("image1"))
            .add(250, 0, getImage("image2"))
            .add(500, 0, getImage("image3"))
            .center()
            .print()
        ,
        newSelector("selection")
            .add(getImage("image1"), getImage("image2"), getImage("image3"))
            .disableClicks()
            .shuffle()
        ,
        newAudio("audio1", audios[0])
            .play()
            .wait()
        ,
        newTimer("break2", 1000)
            .start()
            .wait()
        ,
        newAudio("audio2", audios[1])
            .play()
            .wait()
        ,
        newTimer("break3", 1000)
            .start()
            .wait()
        ,
        newAudio("audio3", audios[2])
            .play()
        ,
        newTimer("break4", 1000)
            .start()
            .wait()
        ,
        getAudio("audio3")
            .wait("first")
    )
    .log("group", row.group)
    .log("item", row.item)
    .log("condition", row.condition)
    .log("audio1", audios[0])
    .log("audio2", audios[1])
    .log("audio3", audios[2])
)

Jeremy