DashedSentence in a PennController trial

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

This topic contains 31 replies, has 8 voices, and was last updated by Jeremy Jeremy 2 weeks, 1 day ago.

Viewing 2 posts - 31 through 32 (of 32 total)
  • Author
    Posts
  • #5696
    Avatar
    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 2 weeks, 1 day ago by Avatar CFWhitwell.
    #5700
    Jeremy
    Jeremy
    Keymaster

    Hello,

    You should probably write your sentences in your table using underscores (_) instead of spaces (or instead of wildcard * if this is what you’ve been using) inside chunks, and reserve space characters to delimit the chunks. For example: This_is_the_first_chunk and_this_is_the_second_chunk. Then just inject the native-Ibex DashedSentence controller, like this:

    //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()
            ,
            newController("DashedSentence", {s: variable.Sentence, display: "in place", hideUnderscores: true})
                .print()
                .log()
                .wait()
                .remove()
            ,
            newText("cq", variable.Question)
                .css("line-height", "2.5")
                .print()
            ,
            newKey("AL")
                .log()
                .wait()
        )
    );

    Jeremy

Viewing 2 posts - 31 through 32 (of 32 total)

You must be logged in to reply to this topic.