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

#5543
Jeremy
Keymaster

Hello Max,

Keep in mind that the original Ibex DashedSentence controller already comes with a mode that lets you show one word at a time. See the Ibex documentation.

I apologize for the functions, I wrote them to be as compact as possible, but it’s not great for readability. Let me rewrite them more clearly:

showWord = (arrayOfWords,showIndex) => "<p style='font-family: monospace;'>" + 
  arrayOfWords.map( (word,n) => {
    const letters = word.replace(/^\s*(\w+).*$/,"$1");  // this only keeps letters (and numbers)
    const punctuation = word.replace(/^\s*\w+/,"");  // this only keeps the punctuation characters
    if (n==showIndex) return "<span>"+letters+"</span>"+punctuation;
    else return "<span style='visibility: hidden;'>"+letters+"</span>"+punctuation;
  } ).join(" ") + "</p>";
dashed = (name, sentence) => {
    const words = sentence.split(" ");  // Use space to break string into array
    return [  // Return an array of key.wait + text.print commands
        [ newText(name,showWord(words)).print() ], // First reveal no word
        ...words.map( (word,index) => [
            newKey(name+"-"+index+"-"+word," ").log().wait()
            , 
            getText(name).text( showWord(words,index) ) // reveal INDEXth word
        ]),
        [ newKey(name+"-last"," ").log().wait() ]
    ].flat(1);
}

As you can see, it’s the regular experessions in showWord that take care of separating the punctuation characters from the rest.

Jeremy