Reply To: Getting variable from csv, based on DropDown selections

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



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 newTrials 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 tests 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 tests

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 tests on the Var element:

    variable => newTrial("demo",
        newText("head", " ")
            .before(newText("b","").text(getVar("namelist")).after(newText(": ")))
  "P1A").success( newImage(variable.P1A) )
  "P1B").success( newImage(variable.P1B) )
  "P1C").success( newImage(variable.P1C) )
  "P2A").success( newImage(variable.P2A) )
  "P2B").success( newImage(variable.P2B) )
  "P2C").success( newImage(variable.P2C) )
  "P3A").success( newImage(variable.P3A) )
  "P3B").success( newImage(variable.P3B) )
  "P3C").success( newImage(variable.P3C) )
        newButton("moveOn", "Continue")