Displaying images based on participants' previous selections

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

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #6221


    I’m trying to create a task where participants are shown images they have selected on previous trials (in my case, to see if they remember the word-image pairing from a previous trial). I started by trying to mock up a toy version based on the tutorial. I have 2 blocks of trials: a learning block, where they see 4 pairs of images, selecting one on each trial, and a test block, where they see those images paired with a distractor image. On the test block, they’d see the image they selected in learning paired with a distractor.

    I make 2 global variables at the beginning of the script–the array and a trial counter for test.

     newVar("testTrial", 0)
    newVar("tracker", [])

    During learning, I use the .success and .failure tests to build an array tracking whether they chose the “two” image (scored as true here). This is built off your helpful post at https://www.pcibex.net/forums/topic/keeping-track-of-participant-accuracy/. And when I log that array (“tracker”), it seems to be working fine, expanding by one value on each learning trial.

        .add( getImage("two") , getImage("one") )
        .test.selected( getImage("two") )

    But I’m having trouble using that array in the test block to determine which image participants see on each trial. I go through the learning and test trials in the same order, so I tried to just use a trial counter to access the appropriate value in the array, and determine which picture to display. But I’m new to javascript/PCIbex and can’t get the syntax to work right pulling in multiple variables; it always ends up undefined. Any help with that (or advice on a better way to do this) would be appreciated.

    //here's the part that needs to be reworked
    newVar("trialChoice").set(getVar("tracker"),v=>v.slice(getVar("testTrial"), getVar("testTrial")+1),
    //test the relevant value of the tracker array for this trial, create the appropriate image
    //distractor image
    newImage("third", variable.DistractorImageFile)
              .size(200, 200),
    //display both images
        .add(0 ,0, getImage("third"))
    • This topic was modified 2 years, 7 months ago by SandyL.


    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:

    AddTable("myTable", `ItemCode,SgImage,PlImage
    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))
            .add( getImage("sg") , getImage("pl") )
            .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()
            .success( newImage(row.SgImage).size(200,200).center().print() )
            .failure( newImage(row.PlImage).size(200,200).center().print() )
    ) )

    Let me know if you have questions


Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.