Reply To: Displaying images based on participants' previous selections

PennController for IBEX Forums Support Displaying images based on participants' previous selections Reply To: Displaying images based on participants' previous selections

#6223
Jeremy
Keymaster

Hi,

The cleanest method in this case is probably to add a column to your table that identifies your items. It can be a number, or a string, whatever makes the most sense to you. This way, you can create a specific global Var element for each of your learning trials, that you look up during the testing phase. It will work as long as you generate the test trials from the same rows as the training trials (or at least rows that reference the same identifying value).

Here is a short example. I use a table with a column named ItemCode, and use the value of that column to name global Var elements specific to that item:

AddHost("https://raw.githubusercontent.com/PennController/TimedPictureSelection/master/chunk_includes/")

AddTable("myTable", `ItemCode,SgImage,PlImage
deer,1deerDenseWood.png,2deerSparseWood.png
fish,1fishSquareTank.png,2fishRoundTank.png
moose,1mooseNewPark.png,2mooseOldPark.png
sheep,1sheepRedPen.png,2sheepBluePen.png`)

Template( row => newTrial( "choose" ,
    newText("Choose an image").print()
    ,
    newCanvas("images", 500, 400)
        .add(  0,0,newImage("sg", row.SgImage).size(200,200))
        .add(300,0,newImage("pl", row.PlImage).size(200,200))
        .center()
        .print()
    ,
    newVar("choice_"+row.ItemCode).global()
    ,
    newSelector("answer")
        .add( getImage("sg") , getImage("pl") )
        .shuffle()
        .wait()
        .test.selected(getImage("sg"))
        .success( getVar("choice_"+row.ItemCode).set('sg') )
        .failure( getVar("choice_"+row.ItemCode).set('pl') )
) )

Template( row => newTrial( "see" ,
    newText("Here is the image you chose").print()
    ,
    getVar("choice_"+row.ItemCode)
        .test.is('sg')
        .success( newImage(row.SgImage).size(200,200).center().print() )
        .failure( newImage(row.PlImage).size(200,200).center().print() )
    ,
    newButton("OK").print().wait()
) )

Let me know if you have questions

Jeremy