DashedSentence in a PennController trial

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

This topic contains 34 replies, has 8 voices, and was last updated by Avatar daniela 1 week, 4 days ago.

Viewing 5 posts - 31 through 35 (of 35 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 4 months, 1 week 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

    #6205
    Avatar
    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

    #6207
    Jeremy
    Jeremy
    Keymaster

    Hi,

    If by “cumulative” you mean that the words that have already been read should not be replaced by underscores when you’re reading the next words, replacing n==i with n<=i should be all you need to do

    Jeremy

    #6216
    Avatar
    daniela
    Participant

    Perfect, thank you!!

Viewing 5 posts - 31 through 35 (of 35 total)

You must be logged in to reply to this topic.