End command

You can use the special end command to control when the trial should end. This is particularly helpful if you want to end the trial prematurely.

Example:

newTextInput("age", "")
    .settings.before("How old are you? ")
    .print()
    .wait()
,
newText("nativeSwahili", "Are you a native speaker of Swahili?")
    .print()
,
newButton("yesSwahili", "Yes")
,
newButton("noSwahili", "No")
    .settings.before( getButton("yesSwahili") )
    .print()
,
newSelector("yesnoSwahili")
    .settings.add( getButton("yesSwahili") , getButton("noSwahili") )
    .wait()
,
getSelector("yesnoSwahili")
    .test.selected( getButton("yesSwahili") )
    .failure( end() ) // Ends the trial prematurely
,
newText("other languages", "If you speak any other language(s), please list up to two (one per line)")
    .print()
,
newTextInput("languageList", "")
    .settings.lines(2)
    .settings.log()
    .print()
,
newButton("finish", "Send")
    .print()
    .wait()

First adds a line asking for age and waits for a press on the enter/return key. Then adds a line of text asking about native fluency in Swahili, two yesno buttons side-by-side below it and waits for a click on either one of them (both being part of the same selector element). If yes was not clicked, then it is the end of the trial. Otherwise, the script proceeds to adding a line of text and an input box inviting to list any other spoken language(s), and a Send button waiting to be clicked.