The new PCIbex Farm is here! Be sure to check out all of its new features and changes.

Link Search Menu Expand Document

Creating elements

Elements contain multimedia content, interactive content, or some combination of the two.


Element types

As of PennController 1.9, PennController has 21 types of elements, including:

  • Text: Text content (multimedia).
  • Image: Image content (multimedia).
  • Key: Keyboard keypresses (interactive).
  • Button: A clickable button (multimedia and interactive).
  • Audio: Audio content that can interact with the experiment script (multimedia and interactive).

We’ll use these five elements in the BasicTutorial experiment.


Creating an element

Create an element by calling a newX(ELEMENT_NAME, ...) function, where:

  • X is a type of element
  • ELEMENT_NAME is the name of the element
  • ... are additional parameters that depend on the element type. For example, if you create an Audio or Image element you’ll also need to specify the name of its source file.
note

Naming an element is technically optional, but we recommend giving every element a name. Naming your elements will make it easier to debug an experiment, and only named elements can be accessed by a getX() function.

instructions

  1. Create an Audio element named "fish-audio" that contains the audio file 2fishRoundTank.mp3.
  2. Create a Text element named "fish-sentence" that contains the string "The fish swim in a tank which is perfectly round."
  3. Create an Image element named "fish-plural" that contains the image 2fishRoundTank.png.

In PennController, all line breaks, tabs, and spaces are optional and purely for human readability, because PennController does not care about whitespace.

However, you must add a comma in between elements. You must also add a comma in between a trial label and the following element.


@// Type code below this line.
@
@// Remove command prefix
@PennController.ResetPrefix(null)
@
@// Experimental trial
!newTrial("experimental-trial",
+    newAudio("fish-audio", "2fishRoundTank.mp3")
+    ,
+    newText("fish-sentence", "The fish swim in a tank which is perfectly round.")
+    ,
+    newImage("fish-plural", "2fishRoundTank.png")
+)

We’ve added some elements, but the trial still doesn’t “do” anything because it doesn’t have any commands. We’ll add some commands soon!

Referring back to an element

Once you create an element, you can refer back to it by calling a getX(ELEMENT_NAME) function, where:

  • X is an element type
  • ELEMENT_NAME is the name of the element

We won’t use a getX() function until 4. Pausing experiment execution but here’s a preview:

PennController.ResetPrefix(null)

newTrial("experimental-trial",
    newAudio("fish-audio", "2fishRoundTank.mp3")
    ,
    // Do some things
    ,
    getAudio("fish-audio")
)