PennController for IBEX › Forums › Support › .test(var) not working
- This topic has 3 replies, 2 voices, and was last updated 4 years, 8 months ago by Jeremy.
-
AuthorPosts
-
March 23, 2020 at 11:34 am #4897crtormaParticipant
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 4 years, 8 months ago by crtorma.
March 23, 2020 at 11:40 am #4899JeremyKeymasterHi 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)),
March 23, 2020 at 11:57 am #4900crtormaParticipantHi 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
March 23, 2020 at 12:54 pm #4901JeremyKeymasterGlad 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() ) )
-
AuthorPosts
- You must be logged in to reply to this topic.