Preloading Resources

By default, all the resources start to preload when the experiment page opens, and each PennController trial checks that the specific resources it uses are preloaded before it starts.

You can change this behavior and have control over when and which resources should be checked for preloading by using the command PennController.CheckPreloaded.

PennController.CheckPreloaded() creates an item that checks that all the resources are preloaded before proceeding. You can also specify that only the resources used by certain items should be checked:

PennController.CheckPreloaded(
    startsWith("practice")
    ,
    startsWith("test")
    ,
    "exitItem"
)

This code will create an item that checks preloading for the resources of all the PennController trials whose label starts with practice or test, or is exitItem, and only those.

Finally, you can pass a number as the last argument to specify a delay (in milliseconds) after which, even if not all the resources have been preloaded, the next item in the sequence should start anyway:

PennController.CheckPreloaded(
    startsWith("test")
    ,
    5000
)

To control when in the flow of your experiment the resources should be checked for preloading, use the label command onto the item generated by PennController.CheckPreload to assign it a label, and refer to it in PennController.Sequence.

Complete Example

PennController.ResetPrefix( null );

PennController.Sequence( "welcome" , "preloadPractice" , startsWith("practice") , "preloadTest" , startsWith("Test") );

PennController.AddHost( "http://files.lab.florianschwarz.net/ibexfiles/PennController/SampleTrials/" );

PennController.CheckPreloaded( startsWith("Practice") )
    .label( "preloadPractice" );

PennController.CheckPreloaded( startsWith("Test") )
    .label( "preloadTest" );

PennController( "welcome" ,
    newText( "message" , "Welcome. The resources are currently being preloaded. The next trial won't start before all the resources for the 'practice' trial are loaded (i.e. 1fishSquareTank.png).")
        .print()
    ,
    newButton("start", "Start")
        .print()
        .wait()
);

PennController( "practice-1" ,
    newImage("tank", "1fishSquareTank.png")
        .print()
    ,
    newText("description", "The tank is round.")
        .print()
    ,
    newKey("validate", "FJ")
        .wait()
);

PennController( "practice-2" ,
    newImage("tank", "1fishSquareTank.png")
        .print()
    ,
    newText("description", "The tank is square.")
        .print()
    ,
    newKey("validate", "FJ")
        .wait()
);

PennController( "Test-1" ,
    newImage("tank", "2fishRoundTank.png")
        .print()
    ,
    newText("description", "The tank is round.")
        .print()
    ,
    newKey("validate", "FJ")
        .wait()
);

PennController( "Test-2" ,
    newImage("tank", "2fishRoundTank.png")
        .print()
    ,
    newText("description", "The tank is square.")
        .print()
    ,
    newKey("validate", "FJ")
        .wait()
);