PennController for IBEX › Forums › Support › Getting variable from csv, based on DropDown selections › Reply To: Getting variable from csv, based on DropDown selections

Hi,
Javascript is immediate, PennController is delayed. More specifically, you cannot dynamically pass values to newImage
(also, how would PennController be able to preload the image file if it had to wait until the trial starts to know which file to use?)
What happens in your case is, as soon as the experiment page is open, all the javascript code is executed immediately (top down). First it creates the varForImg
variable, it creates the setvarForImg
and getvarForImg
functions, it sets the Sequence
, it creates the trial labeled "whoareyou"
, and runs the Template
function to create as many newTrial
s as there are lines in fullList.csv. Because you call setvarForImg
9 times in that newTrial
function, it is called 9 times with each newTrial
creation, and when the script gets to newImage("comicstrip", varForImg)
when creating a trial, the value of varForImg
is always set to the value of variable.P3C
, because that’s the value passed to the most recently executed setvarForImg
function
Then, when you progress through the experiment, as you get to a trial labeled "demo"
, that trial already contains an Image element named "comicstrip"
that points to a file whose name is the value in the P3C
cell for the row from which the trial was created. The first PennController commands to be run as you start a new trial are the test
s on the Var element, whose success
commands have no actual effect (because setvarForImg
returns undefined
, which success
will simply ignore: undefined
is not a PennController command). When the trial’s execution reaches the Image element, it will simply display the the file referenced in the P3C
cell, regardless of the earlier test
s
What you can do instead is delete all references to varForImg
(including the javascript functions) and include all 9 possible newImage
commands in the trial (then PennController will effectively create, and preload, all 9 Image elements per trial) but only execute one of those in the test
s on the Var element:
Template("fullList.csv", variable => newTrial("demo", newText("head", " ") .text(getVar("asdf")) .before(newText("b","").text(getVar("namelist")).after(newText(": "))) .center() .print() , defaultImage.center().print() , getVar("namelist") .test.is("P1A").success( newImage(variable.P1A) ) .test.is("P1B").success( newImage(variable.P1B) ) .test.is("P1C").success( newImage(variable.P1C) ) .test.is("P2A").success( newImage(variable.P2A) ) .test.is("P2B").success( newImage(variable.P2B) ) .test.is("P2C").success( newImage(variable.P2C) ) .test.is("P3A").success( newImage(variable.P3A) ) .test.is("P3B").success( newImage(variable.P3B) ) .test.is("P3C").success( newImage(variable.P3C) ) , newButton("moveOn", "Continue") .center() .print() .wait() ) )
Jeremy