DashedSentence in a PennController trial

PennController for IBEX Forums FAQ / Tips DashedSentence in a PennController trial

This topic contains 0 replies, has 1 voice, and was last updated by Jeremy Jeremy 3 weeks, 5 days ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #4220
    Jeremy
    Jeremy
    Keymaster

    I am working on a general solution to inject native-Ibex-format controllers inside PennController trials, but in the meantime here is a basic illustration of how to code one version of the DashedSentence controller yourself. This is reproducing the default behavior of DashedSentence (self-paced reading mode and dashed display) but it should be easy enough to adapt to your needs if you know a little bit of javascript.

    // This function generates an array of PennController commands
    // It's basically a sequence of text.settings.text() and key.wait()
    // The first parameter is the sentence to display (words should be separated by space characters)
    // The second (optional) parameter determines whether the sentence should be removed at the end
    //
    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() ];
      // 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], " ").settings.log().wait() , // Wait for (and log) a press on Space
                             getText(textName).settings.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;
    }
    
    // Illustration
    //
    PennController(
      newText("instructions", "Click on the button below to start reading")
        .print()
      ,
      newButton("Start reading")
        .print()
        .wait()
        .remove()
      ,
      getText("instructions")
        .remove()
      ,
      // We call the function here
      // Note the ... before dashed because it returns an array, which we want to inject
      //
      ...dashed("The mouse that the cat is chasing runs fast", 'remove')
      ,
      newButton("I'm done")
        .print()
        .wait()
    )
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.