Scale element

description

Represents a horizontal scale.

syntax

newScale(ELEMENT_NAME: string, NUMBER_OF_BUTTONS: int)
  • ELEMENT_NAME: The name of the newly-created element.
  • NUMBER_OF_BUTTONS : Adds the specified number of radio buttons to the element.

since

beta 0.3

example(s)


@newTrial( "mcq" ,
@  newText("Are you male or female?")
@    .print()
@  ,
$  newScale("gender", "male", "female")
$    .labelsPosition("right")
$    .print()
$    .wait()
@)
+ Adds a question and two radio buttons for two possible options.

Action commands

scale.button

syntax

.button()

description

Makes the buttons of the scale appear as clickable text buttons that are framed when selected. If you passed a number when creating the scale, the buttons will be labeled with numbers (starting from 0).

example

click to expand

@newScale("score", 6)
$    .button()
@    .before( newText("score label", "Score: ") )
@    .after( newText("score text", " / 5") )
@    .print()
@    .wait()
  • Adds a scale with 6 horizontally aligned buttons to the screen, labeled from 0 to 5, and waits for a click on one of them.
↑ back to top

scale.callback

syntax

.callback()

description

Executes a sequence of commands whenever a choice is made on the scale. This is particularly useful if, for example, you want to reveal a TextInput element only when a certain option is chosen.

example

click to expand

@
@newTextInput( "other" , "" )
@    .hidden()
@,
@newScale("yarrel",  "Yanny", "Laurel", "other")
@    .labelsPosition( "right" )
@    .after( getTextInput("other") )
$    .callback(
$        getScale("yarrel")
$            .test.selected( "other" )
$            .success( getTextInput("other").visible() )
$            .failure( getTextInput("other").hidden()  )
$    )
@    .print()
↑ back to top

scale.checkbox

syntax

.checkbox()

description

Turns the options into checkoxes that can all independently be on/off.

example

click to expand

@newTrial(
@    newScale("answer", "hello", "world")
$        .checkbox()
@        .print()
@    ,
@    newButton("Hello world")
@        .print()
@        .wait()
)

  • Adds a scale with 3 checkboxes to the screen.
↑ back to top

scale.default

syntax

.default()

description

Makes a value selected by default when printing the scale element. You can pass either an index or a text value as value.

example

click to expand

@
@newScale("score",   "Terrible", "Bad", "Good", "Terrific")
@    .before( newText("left", "The last movie I saw was ") )
@    .labelsPosition("top")
$    .default("Terrific")
@    .print()
  • Adds a scale with 4 horizontally aligned radio buttons to the screen, with their respective labels appear on top of them, selects the right-most button by default, and waits for a click on a radio button.

↑ back to top

scale.horizontal

syntax

.horizontal()

description

Makes the buttons and labels of the scale appear horizontally. This is the default aesthetics of scales.

example

click to expand

@
@newScale("slider",   100)
@    .slider()
@    .vertical()
@    .print()
@,
@newButton("rotate", "Horizontal slider")
@    .print()
@    .wait()
@,
@getScale("slider")
$    .horizontal()
@    .print()
  • Adds a vertical slider to the page and a button which, when clicked, rotates the slider so it appears horizontally.
↑ back to top

scale.keys

syntax

.keys()

description

Respectively associates the scale’s options with the specified keys for selection.

example

click to expand

@newScale("grade",  "A", "B", "C", "D", "E", "F")
@    .labelsPosition("top")
$    .keys()
@    .print()
@,
@newScale(9)
@    .before( newText("Confidence:") )
$    .keys()
@    .print()
@,
@newScale("role",  "TA", "Professor")
@    .labelsPosition("right")
$    .keys("T", "P")
@    .print()
  • Will add three scales onto the screen. Pressing A, B, C, D, E or F will select an option on the first scale, pressing a numeric key from 1 to 9 will select an option on the second scale, and pressing T or P will select an option on the third scale.
↑ back to top

scale.label

syntax

.label()

description

Sets the content of the index-th label (with index starting at 0). This will mostly be useful if you want to use something like an Image element as a label, which cannot be passed as a direct parameter when creating the new Scale.

example

click to expand

@
@newScale("score",  "Bad", "So-so", "Good")
$    .label( 0 , newImage("no.png") )
$    .label( 2 , newImage("ya.png") )
@    .radio()
@    .labelsPosition("top")
@    .before( newText("label", "Score: ") )
@    .center()
@    .print()
@    .wait()
  • Adds a scale with 3 horizontally aligned radio buttons to the screen, instantiated with labels Bad, So-so and Good. The Bad and Good labels are immediately replaced with the images no.png and ya.png, respectively.

↑ back to top

scale.labelsPosition

syntax

.labelsPosition()

description

(Since version 1.0, formerly labels)

example

click to expand

@
@newScale("score",  "Bad", "So-so", "Good")
@    .radio()
$    .labelsPosition("right")
@    .before( newText("label", "Score: ") )
@    .center()
@    .print()
@    .wait()
  • Adds a scale with 3 horizontally aligned radio buttons to the screen, with labels Bad, So-so and Good above their respective buttons, and waits for a click on one of them.

↑ back to top

scale.log

syntax

.log()

description

Adds a line to the result file indicating which button is selected at what time(stamp).

example

click to expand

@newScale("hunger", 5)
@    .before( newText("left", "Right now, I am... very hungry ") )
@    .after( newText("right", " not hungry at all") )
$    .log("first", "last")
@    .print()
@    .wait()
@,
@newButton("validation", "Validate")
@    .print()
@    .wait()
  • Adds a 5-point radio scale and waits for a click on one of its buttons before adding a button to the screen. Only the very first and the very last clicks on the scale will be saved in the results file (if only one selection happened, only one line will be added).
↑ back to top

scale.once

syntax

.once()

description

Disables the scale after the first selection has happened.

example

click to expand

@newScale("hunger", 5)
@    .before( newText("left", "Right now, I am... very hungry ") )
@    .after( newText("right", " not hungry at all") )
$    .once()
@    .print()
@    .wait()
  • Adds a 5-point radio scale and waits for a click on one of its buttons, after which selection cannot be changed and a button appears below the scale.
↑ back to top

scale.radio

syntax

.radio()

description

Makes the buttons of the scales appear as radio buttons.

example

click to expand

@newScale("score",   "Terrible", "Bad", "Good", "Terrific")
@    .before( newText("left", "The last movie I saw was ") )
$    .radio()
@    .labelsPosition("top")
@    .print()
@    .wait()
  • Adds a scale with 4 horizontally aligned radio buttons to the screen, with their respective labels appear on top of them, and waits for a click on a button.
↑ back to top

scale.select

syntax

.select()

description

Selects the specified option on the scale.

example

click to expand

@newText("What programming language is PennController based on?")
@    .print()
@,
@newScale("answer",  "C++", "JavaScript", "Python", "R")
@    .labelsPosition("right")
@    .print()
@,
@newButton("Check my answer")
@    .print()
@    .wait( getScale("answer").test.selected() )
@,
@getScale("answer")
@    .test.selected("JavaScript")
@    .success(
@        newText("Good job!")
@            .print()
@    )
@    .failure(
@        newText("Wrong...")
@            .print()
@    )
@,
@getScale("answer")
$    .select("JavaScript")
@    .disable()
  • Adds a question, a scale with four options and a button onto the page, then waits until the button is clicked while an option is selected. Once the button is clicked, prints a different feedback message depending on whether JavaScript is selected, then selects the JavaScript option (the correct answer) and disables the scale.

↑ back to top

scale.slider

syntax

.slider()

description

Transforms the scale into a slider. Note that sliders always have a default value in order to place their cursor. If you do not use the settings command default, the central (or next-to-central) value will be used.

example

click to expand

@
@newScale("slider",   100)
$    .slider()
@    .print()
  • Adds a 100-point slider to the page and a validation button.
↑ back to top

scale.unselect

syntax

.unselect()

description

Will unselect the option currently selected.

example

click to expand

@newScale("score", 10)
@  .print()
@,
@newButton("Unselect")
$  .callback( getScale("score").unselect() )
@  .print()
  • Prints a 10-point radio button scale and a button reading Unselect which, when clicked, unselects the currently selected button on the scale.
↑ back to top

scale.vertical

syntax

.vertical()

description

Makes the buttons and labels of the scale appear vertically, with the initially left-most value to the bottom and the initially right-most value on top.

example

click to expand

@newScale("slider",   100)
@    .slider()
$    .vertical()
@    .print()
  • Adds a 100-point vertical slider to the page and a button to validate.
↑ back to top

scale.wait

syntax

.wait()

description

Waits until one of the buttons is clicked before evaluating and executing the next commands.

example

click to expand

@newScale("hunger", 5)
@    .before( newText("left", "Right now, I am... very hungry ") )
@    .after( newText("right", " not hungry at all") )
@    .print()
$    .wait()
  • Adds a 5-point radio scale to the screen and waits for a click on one of its buttons.
↑ back to top


Test commands

scale.test.selected

syntax

.test.selected()

description

Tests whether a button is selected.

example

click to expand

@newScale("score",   5)
@    .before( newText("label", "Score: ") )
@    .print()
@,
@newButton("validation", "Validate")
@    .print()
@    .wait( getScale("score").test.selected() )
  • Adds a 5-point radio-button scale and a Validate button to the screen. Clicking on the Validate button is successful only when a radio button is selected.
↑ back to top


Table of contents