getting variable from csv, based on a text in a column

PennController for IBEX Forums Support getting variable from csv, based on a text in a column

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

    Hi Jeremy,
    after a day of going through the forum, and trying a few things out, I give up and have to ask you:
    I want to color certain elements of my texts (which are presented in a triangle canvas) based on a code in a column of my .csv list. I have no idea how to do this. I guess it should work with, but I am really having a hard time translating what has been suggested here in some threads to my script. I appreciate any help!

    Here’s my csv list:


    and here my script:

    Template("draft_list_2.csv", row =>
        newText("top", row.TOP),
        newText("left", row.LEFT),
        newText("right", row.RIGHT),
        newCanvas("trialCanvas", 200,200)
            .settings.add( 50,0, getText("top"))
            .settings.add(-30,140, getText("left"))
            .settings.add(140,140, getText("right"))
      newTextInput("response", "")

    Now, based on the column “Coloring_code”, I want to either have the “top” (TOO), the “left” (OLO), or the “right” (OOR) text element printed in blue, and no coloring with OOO.
    I am sorry, I’m not very experienced with coding. Which is why I feel a little embarrassed, and was hesitant to ask publicly.
    Could you help me? It is greatly appreciated!

    I also have a question about Setcounter: I have 12 different lists (named group in my csv), who should be counterbalanced between participants. But starting the next list only after one participant has finished the previous is a bit late. I would like it to present the next list when Participant x is done with the practice trials and clicks on “continue to experiment”. I found this code here:

    SetCounter("counter", "inc", 1);

    and set in in the Sequence after “practice” and before “experiment” – but it did not seem to work. I still get list 2 (L2) presented, since I finished a trial run once.

    thank you for any suggestion!


    Hi Anna,

    I know we’ve already addressed these points by email, but I’ll post answers here too in case someone finds this post and wants answers

    1. It’s actually better to reserve Var elements for values that will only get set upon runtime. Column values are all preset (since they come directly from a pre-existing table) so using the javascript ternary conditional operator is to be preferred:

        newText("top", row.TOP).color(row.Coloring_code=="TOO" ? "blue" : "black"),
        newText("left", row.LEFT).color(row.Coloring_code=="OLO" ? "blue" : "black"),
        newText("right", row.RIGHT).color(row.Coloring_code=="OOR" ? "blue" : "black"),

    2. Including SetCounter("counter", "inc", 1); in your experiment will increase the counter earlier than by default, but the new value concerns the next participant: the current run will keep the same counter value that was assigned when the page was open. However, nothing guarantees that the next participant will indeed complete the experiment, and so you still risk ending up with unbalanced group assignments in your results. At the end of the day, there’s no way to *automatically* ensure you’ll have a balanced distribution, which is why the recommended method is to recruit participants using the method described int the tutorial, so you can easily manually control group assignment


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