PennController for IBEX › Forums › FAQ / Tips › DashedSentence in a PennController trial › Reply To: DashedSentence in a PennController trial
October 16, 2020 at 5:31 am
#6205
daniela
Participant
Hi Jeremy,
I’ve had some successful Ibex experiments using the dashed function you wrote for me some months ago, and am now trying to adapt it for cumulative presentation. I’ve been playing with the getText()
line in the function but haven’t been able to get it to work. Do you have a fix for this?
// create dashed function
dashed = (sentence, remove) => {
let words = sentence.split('*'), blanks = words.map(w=>w.split('').map(c=>'_').join('') ); // 'sentence.spilot('*')' = '*' defines the chunk boundaries (in the .csv)
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","courier") .settings.css("font-size", "20px") .settings.center()]; // COURIER 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;
};
Many thanks!
Daniela