PennController for IBEX › Forums › Support › Filtering a table with a global variable
- This topic has 1 reply, 1 voice, and was last updated 31 minutes ago by
Arsen Anisimov.
-
AuthorPosts
-
August 16, 2025 at 2:20 pm #11117
Arsen Anisimov
ParticipantDear Jeremy and everyone,
I have an experimental design with several blocks. In the demo version that I print in the comments, there’re two blocks. In each block I want to display sentences about a particular topic. The order of the topics can be randomised but sentences about different topics should not be shuffled with each other. There’s one sentence (text_type: late) that should be displayed _at the end_ of every block. Sentences of other types (test, true, fals) are displayed in random order.
So I created two Templates:
– In the first, I use the table and filter all the sentence that are not of the type «late». The number of the block is assigned automatically (https://www.pcibex.net/forums/topic/using-group-for-two-different-blocks/). Then I to saved the number of the block to a variable blockNum.
– In the second, I use the same table and filter only the sentence with type «late» and with the same number of the block. If everything works right, there will be exactly one sentence.Unfortunately, I cannot get the value from the global variable to filter the table in the second block.
I tried and it didn’t work:
.filter( row => (row.text_type == "late") && (row.block == getVar("blockNum")._element.value) ) .filter("block", blockNum) .filter("block".toString(), getVar("blockNum").toString()) .filter("block".toString(), getVar("blockNum")._element.value) .filter("block".toString(), getVar("blockNum")._element.value.toString())
This is the first block:
Template( GetTable( "list.csv" ) .filter( row => row.text_type != "late" ) // , row => newTrial("block-"+row.block, newVar("blockNum").global().set( v => row.block.toString() ) , newText("backgr", row.backgr) .print() , newImage("img", row.img) .center() .print() , newImage("table", row.table) .center() .print() , newButton("Show a sentence") .center() .print() .wait() .remove() , newText(row.text) .center() .print() , newVar("RT").global().set( v => Date.now() ) , newText("This sentence is ...") .print() , newScale("answer", "True", "Indeterminate", "False") .labelsPosition("right") .settings.css("font-size", "14pt") .center() .print() .wait() , getScale("answer") .log() , newButton("next", "Next") .center() .print() .wait( getScale("answer").test.selected()) , getVar("RT").set( v => Date.now() - v ).log() ) .log("id_item", row.id_item) .log("text_type", row.text_type) .log("group", row.group) .log("block", row.block) );
The second block:
Template( GetTable( "list.csv" ) .filter( row => (row.text_type == "late") && (row.block == getVar("blockNum")._element.value) ) // The problem is here. , row => newTrial("later-block-"+row.block, newText("backgr", row.backgr) .print() , newImage("img", row.img) .center() .print() , newImage("table", row.table) .center() .print() , newButton("Show a sentence") .center() .print() .wait() .remove() , newText(row.text) .center() .print() , newVar("RT").global().set( v => Date.now() ) , newText("This sentence is ...") .print() , newScale("answer", "True", "Indeterminate", "False") .labelsPosition("right") .settings.css("font-size", "14pt") .center() .print() .wait() , getScale("answer") .log() , newButton("next", "Next") .center() .print() .wait( getScale("answer").test.selected()) , getVar("RT").set( v => Date.now() - v ).log() ) .log("id_item", row.id_item) .log("text_type", row.text_type) .log("group", row.group) .log("block", row.block) );
A demo of the table:
group,block,id_item,backgr,img,table,text,text_type A,1,i_sw_test,"This topic is about switches.",switches.png,sw_i.png,Switch A is allowed to be up.,test A,1,i_sw_fals,"This topic is about switches.",switches.png,sw_i.png,The switches are not allowed to be down at the same time.,fals A,1,i_sw_late,"This topic is about switches.",switches.png,sw_i.png,This sentence should be displayed at the end of the topic about switches.,late A,2,i_tr_test,"Let’s speak about trains.",trains_i.png,tr_i.png,Train A is allowed to go through the intersection.,test A,2,i_tr_test,"Let’s speak about trains.",trains_i.png,tr_i.png,Train B is not allowed to go through the intersection.,test A,2,i_tr_late,"Let’s speak about trains.",trains_i.png,tr_i.png,The last sentence about trains.,late
Could you help me please to understand how to filter the table, i.e., how to properly save and get the value of the variable blockNum during filtering?
Or maybe there’re better ways to implement the design?
Best regards,
Arsen-
This topic was modified 1 day, 16 hours ago by
Arsen Anisimov.
-
This topic was modified 1 day, 16 hours ago by
Arsen Anisimov.
-
This topic was modified 1 day, 16 hours ago by
Arsen Anisimov.
August 18, 2025 at 6:40 am #11121Arsen Anisimov
ParticipantI have figured it out. PCIbex auto-magically saves the number of the block which was randomly chose in the first Template and uses it in the second, so my code looks like that:
I want my experiment to start with any topic (block) so I randomize them:
var blocks = [[randomize("block-1"), "later-block-1"], [randomize("block-2"), "later-block-2"], [randomize("block-3"), "later-block-3"], [randomize("block-4"), "later-block-4"]]; fisherYates(blocks); Sequence("welcome", "consent", blocks[0][0], blocks[0][1], blocks[1][0], blocks[1][1], blocks[2][0], blocks[2][1], blocks[3][0], blocks[3][1], SendResults(), "end")
So “later-blocks” always follow regular “blocks”.
//block- Template( GetTable( "list.csv" ) .filter( row => row.text_type != "late" ) , row => newTrial("block-"+row.block, // ) .log("id_item", row.id_item) .log("text_type", row.text_type) .log("group", row.group) .log("block", row.block) ); //later-block- Template( GetTable( "list.csv" ) .filter( row => row.text_type == "late" ) , row => newTrial("later-block-"+row.block, // ) .log("id_item", row.id_item) .log("text_type", row.text_type) .log("group", row.group) .log("block", row.block) );
-
This topic was modified 1 day, 16 hours ago by
-
AuthorPosts
- You must be logged in to reply to this topic.