Reply To: DashedSentence in a PennController trial

PennController for IBEX Forums FAQ / Tips DashedSentence in a PennController trial Reply To: DashedSentence in a PennController trial

#5236
Jeremy
Keymaster

Hello Matthias,

I don’t think the native-Ibex DashedSentence controller offers that option. However following option 2 from my first message, I came up with two short javascript functions that reasonably reproduce DashedSentence’s behavior:

showWord = (s,i) => '<p>'+s.map((w,n)=>`
        <span${(i===n?"":' style=\'border-bottom:solid 1px black;\'><span style=\'visibility:hidden;\'')}'>
        ${w.replace(/^\s*(\w+).*$/,"$1")}${(i===n?"":'</span>')}</span>${w.replace(/^\s*\w+/,'')}`).join(' ')+'</p>'

dashed = (name, sentence) => {
    let words = sentence.split(' ');
    return [
        [newText(name, showWord(words)).print()], 
        ...words.map( (w,i) => [newKey(`${name}-${i}-${w}`," ").log().wait() , getText(name).text(showWord(words,i))] ),
        [newKey(`${name}-last`," ").log().wait()]
    ].flat(1);
}

Once you’ve added that bit of code at the top of your script, you can then use it like this:

newTrial(
    dashed("test", "Nico and Lotte fought together for a fair and equal world. Their collaboration proved to be extremely successful.
Nico inspired Lotte because he always wanted to take immediate action when he saw injustice.") , getText("test").remove() , newButton("next").print().wait() )

Just make sure you don’t insert a space before <br> otherwise it will be considered a word.

As you can see, the script creates a Text element whose name you provide as the first argument of dashed (here, test) so you can play with that element later (I decided to take it off the screen once complete, using remove).

You’ll get keypress events reported in your results file (along with a timestamp), with names like test-0-Nico, test-1-and, etc.

Incidentally, it also take care of the key-release problem that Christoph reported.

Let me know if you have any questions.

Jeremy