⚠ This website is the beta version of the PCIbex documentation and is still under development. ⚠
Link Search Menu Expand Document

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

instructions

  1. Create a Key named "keypress" that “listens” for a press of the F or J key.
  2. Call the wait command on the "keypress" Key to pause experiment script execution until the participant presses a valid key, in this case the F or J 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.

instructions

  • 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:
    1. Audio playback finishes.
    2. The wait command on the "keypress" Key pauses experiment script execution. The participant presses a valid key.
    3. The wait("first") command on the "fish-audio" Audio pauses experiment script execution. PennController waits for any end-of-audio-playback event.
    4. 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:
    1. Audio playback finishes.
    2. The wait command on the "keypress" Key pauses experiment script execution. The participant presses a valid key.
    3. The basic wait command on the "fish-audio" Audio pauses experiment script execution. PennController starts waiting for an end-of-audio-playback event.
    4. 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.