Reply To: self-paced reading with image element in the middle of the sentence

PennController for IBEX Forums Support self-paced reading with image element in the middle of the sentence Reply To: self-paced reading with image element in the middle of the sentence

#6717
Jeremy
Keymaster

Hi Sarah,

In this case, you’re probably better off re-coding DashedSentence’s function yourself. Here’s a suggestion, add this to your script (tested with PennController 1.9):

addToDash = (commands,element,previousElement) => {
    id = element._element.id;
    type = element._element.type;
    if (previousElement && previousElement._runPromises && previousElement._runPromises instanceof Function){
        previousId = previousElement._element.id;
        previousType = previousElement._element.type;
        previousElement = window['get'+previousType](previousId).hidden()
    }
    commands.push(
        getKey("nextDash").wait(),
        previousElement,
        window['get'+type](id).log().print( getText("container") )
    )
}
myDash = (...args) => {
    commands = [
        newKey("nextDash", " ").log("all"),
        newText("container", "").css({display:"flex",'flex-flow':'row wrap'}).print()
    ];
    previousElement = null;
    args.forEach(a => {
        if (typeof(a)=="string") a = a.split(' ').forEach( s=>{
            newElement = newText(s);
            commands.push(newElement);
            addToDash(commands,newElement,previousElement);
            previousElement = newElement;
        });
        else if (a._runPromises && a._runPromises instanceof Function) {
            newElement = window['get'+a._element.type](a._element.id);
            addToDash(commands,newElement,previousElement);
            previousElement = newElement;
        }
    })
    return commands;
}

Then you can use it like this:

newTrial( "experiment",
    newImage("ball","ball.png").size(50,50).print().remove()
    ,
    ...myDash("This is a very long sentence to see if linebreaks will be automatically handled", getImage("ball"), "in a satisfactory way, despite there being an Image element in the middle of this very very very very long sentence!")
    ,
    getKey("nextDash").wait()
)

Note that I print and immediately remove the Image element before using the function, as otherwise PennController has trouble printing it right. The participant shouldn’t see anything, just make sure to print any Image element you insert in myDash beforehand

Let me know if you have questions

Jeremy