PennController for IBEX › Forums › FAQ / Tips › DashedSentence in a PennController trial › Reply To: DashedSentence in a PennController trial
June 22, 2020 at 1:18 pm
#5696
CFWhitwell
Participant
I am looking to present chunks of a sentence in place in a self-paced reading task. The code runs now, but not in the format I want (it is now displaying full sentence with empty blanks; I want in place words/chunks)
I believe the changes need to be made in the line starting with “let words =” in order to remove the dashes and make the words appear in place, but I’m at a loss for what I need to use.
This is the code:
dashed = (sentence, remove) => { let words = sentence.split('*'), blanks = words.map(w=>w.split('').map(c=>'_').join('') ); let textName = 'dashed'+words.join(''); // We'll return cmds: the first command consists in creating (and printing) a Text element with dashes let cmds = [ newText(textName, blanks.join(' ')).print() .settings.css("font-family","times new roman")]; // times new roman as font // We'll go through each word, and add two command blocks per word for (let i = 0; i <= words.length; i++) cmds = cmds.concat([ newKey('dashed'+i+words[i], " ").log().wait() , // Wait for (and log) a press on Space getText(textName).text(blanks.map((w,n)=>(n==i?words[n]:w)).join(' ')) ]); // Show word if (remove) // Remove the text after the last key.wait() is parameter specified cmds.push(getText(textName).remove()); return cmds; } //Introduction screen with button newTrial( newText("intro", "These are the instructions. Click to start.") .print() , newButton("Start") .print() .wait() .remove() ); //Experimental task with in place self-paced reading followed by a comprehension question. Sentence and question are pulled from the table. Template(variable => newTrial( newText("test", "Press space bar to read the sentence.") .css("color", "red") .css("font-syle", "italic") .css("line-height", "1.5") .print() , newText("test", "Press <b>A</b> for true. Press <b>L</b> for false.") .css("font-syle", "italic") .css("line-height", "1.5") .print() , ...dashed(variable.Sentence, 'remove') , newText("cq", variable.Question) .css("line-height", "2.5") .print() , newKey("AL") .log() .wait() ) );
- This reply was modified 4 years, 4 months ago by CFWhitwell.