Function element

Action commands
Test commands

description

Embeds a JavaScript function.

syntax

newFunction(ELEMENT_NAME: string, FUNCTION)
  • ELEMENT_NAME: The name of the newly-created element.
  • FUNCTION : A JavaScript function.

since

beta 0.3

example(s)

+ Passes a Javascript function to the controller.

@newFunction(()=>$(".secret")
@                  .css("background","yellow") )
@                  .call()
+ This function colors the background of elements with the id "secret" to yellow.

Action commands

function.call

syntax

.call()

description

Executes the function.

example

click to expand

@
@newFunction("setKeyTime", function(){ this.keyTime = Date.now(); }),
@newFunction("keyTimerDelay", function(){ return Date.now() - this.keyTime > 10; }),
@newButton("Start", "Start")
@    .print()
@    .wait(),
@newText("instrutions", "Quick, you have one second to press the T key!")
@    .print(),
@newTimer("quick", 1010)
@    .start(),
@newKey("t", "T")
@    .wait(),
$getFunction("setKeyTime")
$    .call(),
@getTimer("quick")
@    .wait("first"),
@getFunction("keyTimerDelay")
@    .test.is(true)
@    .success(
@        newText("success", "Good job!")
@            .print()
@    )
@    .failure(
@        newText("failure", "Too slow...")
@            .print()
@    ),
@getButton("Start")
@    .wait()
↑ back to top


Test commands

function.test.is

syntax

.test.is()

description

Executes the function and tests the value it returns. If you specify no value, it yields success if the return value is 0, null, undefined or false.

example

click to expand

@newFunction("timestampMultipleOfThree", () => Date.now() % 3 )
@,
@newText("missed", "Bad luck, try again!")
@    .color("red")
@    .bold()
@,
@newButton("myButton", "Click me")
@    .print()
@    .wait(
@        getFunction("timestampMultipleOfThree")
$            .testNot.is()
$            .success( getText("missed").remove() )
$            .failure( getText("missed").print() )
@    )
  • Adds a button to the screen whose clicks are validated only if happening at a time when the timestamp is not a multiple of 3 (i.e., the modulo value returned by the function is different from 0).
↑ back to top


Table of contents