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 CheckPreloaded. [js]CheckPreloaded()[/js] 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:

[js]
CheckPreloaded(
startsWith(“practice”)
,
startsWith(“test”)
,
“exitItem”
)
[/js]

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:

[js]
CheckPreloaded(
startsWith(“test”)
,
5000
)[/js]

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.

[js try=”data”]Sequence( “welcome” , “preloadPractice” , startsWith(“practice”) , “preloadTest” , startsWith(“Test”) );

CheckPreloaded( startsWith(“practice”) )
.label( “preloadPractice” );

CheckPreloaded( startsWith(“Test”) )
.label( “preloadTest” );

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

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

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

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

newTrial( “Test-2” ,
newImage(“tank”, “2fishRoundTank.png”)
.print()
,
newText(“description”, “The tank is square.”)
.print()
,
newKey(“validate”, “FJ”)
.wait()
);
[/js]