Pausing experiment execution
Interactive elements and commands can pause experiment script execution, in order to give participants time to interact with the screen.
Some h2
audio.wait
: Pauses experiment script execution until audio playback finishes.key.wait
: Pauses experiment script execution until a valid keypress.- Also:
button.wait
,controller.wait
,dropdown.wait
, and more.
- Create a
Key
named"keypress"
that “listens” for a press of theF
orJ
key. - Call the
wait
command on the"keypress"
Key
to pause experiment script execution until the participant presses a valid key, in this case theF
orJ
key.
@// Type code below this line.
@
@// Remove command prefix
@PennController.ResetPrefix(null)
@
@newTrial("experimental-trial",
@ newAudio("fish-audio", "2fishRoundTank.mp3")
@ .play()
@ ,
@ newText("fish-sentence", "The fish swim in a tank which is perfectly round.")
@ .print()
@ ,
@ newImage("fish-plural", "2fishRoundTank.png")
@ .print()
+ ,
+ newKey("keypress", "FJ")
+ .wait()
@)
If the participant presses the F
or J
key while the audio file is still playing, the trial ends and the experiment sends its results while the audio file continues playing.
However, you might want a different sequence of events:
- Option 1: End trial and stop audio playback after a valid keypress.
- Option 2: End trial after audio playback finishes, instead of after a valid keypress.
- Option 3: End trial after audio playback finishes or after a valid keypress, whichever comes second.
In this experiment we’ll use Option 3, but provide all options for reference.
Option 1: click for more details
Option 1: End trial and stop audio playback after a valid keypress
- Call the
stop
command on the"fish-audio"
Audio
to stop audio playback.
@// Type code below this line.
@
@// Remove command prefix
@PennController.ResetPrefix(null)
@
@// Experimental trial
@newTrial("experimental-trial",
@ newAudio("fish-audio", "2fishRoundTank.mp3")
@ .play()
@ ,
@ newText("fish-sentence", "The fish swim in a tank which is perfectly round.")
@ .print()
@ ,
@ newImage("fish-plural", "2fishRoundTank.png")
@ .print()
@ ,
@ newKey("keypress", "FJ")
@ .wait()
+ ,
+ getAudio("fish-audio")
+ .stop()
@)
Option 2: click for more details
Option 2: End trial after audio playback finishes, instead of after a valid keypress
- Call the
wait
command on the"fish-audio"
Audio
(instead of on the"keypress"
Key
) to pause experiment script execution until audio playback finishes.
@// Type code below this line.
@
@// Remove command prefix
@PennController.ResetPrefix(null)
@
@// Experimental trial
@newTrial("experimental-trial",
@ newAudio("fish-audio", "2fishRoundTank.mp3")
@ .play()
@ ,
@ newText("fish-sentence", "The fish swim in a tank which is perfectly round.")
@ .print()
@ ,
@ newImage("fish-plural", "2fishRoundTank.png")
@ .print()
@ ,
@ newKey("keypress", "FJ")
- .wait()
+ ,
+ getAudio("fish-audio")
+ .wait()
@)
End trial after audio playback finishes or valid keypress
To end the trial after audio playback finishes or after a valid keypress, whichever comes second, pause the experiment script execution at the "keypress"
Key
and at the "fish-audio"
Audio
.
- Call the
wait("first")
command on the"fish-audio"
Audio
to pause experiment script execution until an end-of-audio-playback event.
@// Type code below this line.
@
@// Remove command prefix
@PennController.ResetPrefix(null)
@
@// Experimental trial
@newTrial("experimental-trial",
@ newAudio("fish-audio", "2fishRoundTank.mp3")
@ .play()
@ ,
@ newText("fish-sentence", "The fish swim in a tank which is perfectly round.")
@ .print()
@ ,
@ newImage("fish-plural", "2fishRoundTank.png")
@ .print()
@ ,
@ newKey("keypress", "FJ")
@ .wait()
+ ,
+ getAudio("fish-audio")
+ .wait("first")
@)
Some h3
When called on an Audio
element, the wait("first")
command and the plain wait
command differ in an important way:
wait("first")
: tells PennController to wait for any end-of-audio-playback event.wait
: tells PennController to start waiting for an end-of-audio-playback event.
This difference is important in the situation where audio playback finishes before the participant presses a valid key:
- Using the
wait("first")
command:- Audio playback finishes.
- The
wait
command on the"keypress"
Key
pauses experiment script execution. The participant presses a valid key. - The
wait("first")
command on the"fish-audio"
Audio
pauses experiment script execution. PennController waits for any end-of-audio-playback event. - Audio playback has already finished, which satisfies the
wait("first")
command. Experiment script execution continues immediately and the trial ends.
- Using the plain
wait
command:- Audio playback finishes.
- The
wait
command on the"keypress"
Key
pauses experiment script execution. The participant presses a valid key. - The basic
wait
command on the"fish-audio"
Audio
pauses experiment script execution. PennController starts waiting for an end-of-audio-playback event. - However, audio playback has already finished, and PennController will never detect an end-of-audio-playback event. The basic
wait
command cannot be satisfied, and experiment script execution pauses indefinitely.