Preloading Resources

By default, all the resources start to preload when the experiment page opens, and every PennController trial, when executed, will pause the experiment if the specific resources it uses have not yet preloaded.

You can change this behavior and control when and which resources should be checked for preloading by using the command PennController.CheckPreloaded. PennController.CheckPreloaded() creates a PennController trial which, when executed, will pause the experiment until all the resources are preloaded. You can also be more specific and only target resources used by PennController trials with certain labels:

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

This code will create a PennController trial which, when executed, will pause the experiment until preloading is complete for all the resources used by PennController trials whose labels start with practice, by PennController trials whose labels start with test, and by PennController trials whose labels correspond exactly to exitItem, and only by those.

Use the .label command on the PennController trial to label it so you can control when in the flow of your experiment the resources will be checked for preloading (see full example below).

You can also 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 trial in the experiment flow should start anyway:

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

Complete Example

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

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


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()
);