PennController for IBEX › Forums › Support › Displaying images based on participants' previous selections
- This topic has 1 reply, 2 voices, and was last updated 3 years, 11 months ago by Jeremy.
-
AuthorPosts
-
October 19, 2020 at 4:10 pm #6221SandyLParticipant
Hi,
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) .global(), newVar("tracker", []) .global()
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.
newSelector("answer") .add( getImage("two") , getImage("one") ) .shuffle() .wait() .log() .test.selected( getImage("two") ) .success(getVar("tracker").set(v=>[...v,true])) .failure(getVar("tracker") .set(v=>[...v,false]))
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), getVar("testTrial").set(v=>v+1), //test the relevant value of the tracker array for this trial, create the appropriate image getVar("trialChoice") .test.is(true) .success( newImage("contingent",variable.PluralImageFile) .size(200,200)) .failure( newImage("contingent",variable.SingularImageFile) .size(200,200)), //distractor image newImage("third", variable.DistractorImageFile) .size(200, 200), //display both images newCanvas(450,200) .add(0 ,0, getImage("third")) .add(250,0,getImage("contingent")) .print()
- This topic was modified 3 years, 11 months ago by SandyL.
October 19, 2020 at 5:20 pm #6223JeremyKeymasterHi,
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
-
AuthorPosts
- You must be logged in to reply to this topic.