.test(var) not working

PennController for IBEX Forums Support .test(var) not working

This topic contains 3 replies, has 2 voices, and was last updated by Jeremy Jeremy 1 week, 3 days ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #4897
    Avatar
    crtorma
    Participant

    Hi Jeremy,

    I have a segment of code that looks like this:

    newVar('left_word',""),
        newVar('right_word',""),
        newVar('name_order', row.Naming_Order),
        getVar('name_order')
            .test.is('AB')
            .success(
                getVar('left_word')
                    .set(row.A_set_image),
                getVar('right_word')
                    .set(row.B_set_image)
                )
            .failure(
                getVar('left_word')
                    .set(row.B_set_image),
                getVar('right_word')
                    .set(row.A_set_image)
                )

    Basically, testing if the column ‘Naming_Order’ is ‘AB’ or something else, and assigning values to two variables accordingly. However, the .test() function doesn’t seem to be working — the two variables appear as “” in every trial (the value they are initialized with). I’ve determined with .log() that ‘name_order’ is set the correct value, and I’ve double checked all the names of things and tried using numerals for the test argument in the code and CSV rather than AB/etc., but the .test() still doesn’t seem to be running at all. Do you know why this may be / how to fix it? Thanks in advance.

    Best,

    Cindy

    • This topic was modified 1 week, 3 days ago by Avatar crtorma.
    #4899
    Jeremy
    Jeremy
    Keymaster

    Hi Cindy,

    How and where do you access the left_word and right_word Var elements? If you need to access them in a different trial than they are set, you need to make them global.

    Also, are you sure that there’s no standing space character before or after AB in your cell values?

    If you’re only using the name_order Var element to conditionally set the left_word and right_word ones, there’s a simple javascript way of doing it:

    newVar('left_word',(row.Naming_Order == 'AB' ? row.A_set_image : row.B_set_image)),
    newVar('right_word',(row.Naming_Order == 'AB' ? row.B_set_image : row.A_set_image)),
    #4900
    Avatar
    crtorma
    Participant

    Hi Jeremy,

    The variables only needed to be accessed in the trial they were set in, and I made sure there was no additional spaces in the CSV columns.

    The shorthand notation seems to have fixed the issue, though, so thank you!

    Best,

    Cindy

    #4901
    Jeremy
    Jeremy
    Keymaster

    Glad that fixed the issue

    Just a note that the following works just fine (using PennController 1.7) so maybe the problem was due to some other interaction?

    AddTable("testTable", `Naming_Order,A_set_image,B_set_image
    AB,boyTalking.png,girlTalking.png
    BA,boyTalking.png,girlTalking.png`)
    
    Template("testTable", row=>
        newTrial(
            newVar('left_word',""),
            newVar('right_word',""),
            newVar('name_order', row.Naming_Order),
            getVar('name_order')
                .test.is('AB')
                .success(
                    getVar('left_word')
                        .set(row.A_set_image),
                    getVar('right_word')
                        .set(row.B_set_image)
                    )
                .failure(
                    getVar('left_word')
                        .set(row.B_set_image),
                    getVar('right_word')
                        .set(row.A_set_image)
                    )
            ,
            newText().text( getVar("left_word") ).print(),
            newText().text( getVar("right_word") ).print()
            ,
            newButton("next").print().wait()
        )
    )
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.