Menu

Scripting

Csaba Skrabák

Your development environment can be scripted. Please note that scripting is not intended to write programs for users. It can be used for testing the development environment, or maybe initializing it for special programming tasks. Scripts cannot be run on the lightweight runner that you download. Scripts cannot run loops or conditionals, they always execute line by line from the beginning to the end.

If you want programming stuff, this page is not for you. You can start programming with the tutorials, which you can find on the try-it page.

Scripting language

Here is a list of keywords that can be used in scripts:

  • SCRIPT: needs to be the first line of every script.
  • TIMEOUT: specify how much time the script runner is willing to wait for a line to finish execution. Can be set several times in a script, the timeout value in effect will be the latest encountered TIMEOUT argument. Argument is meant in milliseconds.
  • Assertions on the output:
    • EXPECT: expect the text in the argument to be output by the program running.
    • BETWEEN: expect that a line printed is a number between the two arguments.
    • UNEXPECT: expect that the specified text is not found in the unprocessed output.
    • PASS: expect that there is no parse or run-time error, and the program finished running.
    • Non-matching lines are ignored by EXPECT and BETWEEN, the matching line is consumed from the buffer where each of the assertions look for lines. UNEXPECT does not consume.
    • Failures and successes are logged on the browser console.
  • BREAK: simulate a user break (Esc key pressed).
  • ENTER: simulate user input. You can omit the ENTER keyword, unless you want to simulate entering text that starts with one of the keywords.
  • BUFFER: set up event codes that the program should receive once it runs.
  • CAPTURE: capture a screenshot to the Misc screen (requires extra library not available on the try-it page.)
  • RUN: start the program that is in the runner with the events BUFFERed. If you want to simulate the RUN interactive command instead, say ENTER RUN.

Lines that do not start with a scripting keyword mentioned above are executed as interactive [Commands] when the readyprompt is active, or user input when the program stopped for INPUT.

Scripting language has no convenience features like case insensitiveness or space normalization. Use a single space to separate keywords from their arguments. Use uppercase letters for the keywords.

Running scripts

Copy the script in the program listing editbox. If the entered text conforms with the scripting language format (i.e. has the SCRIPT header line) then a PLAY button appears. Before pressing it, make sure that you have a copy of the script. You may lose the text when the execution reaches a NEW or OLD command. Press PLAY to start the script.

How script engine works

It will pick the next line from the script each time the cursor starts its blinking mode. When there is a program running in the imeight runner, the script engine waits idle until there is input expected or the program is terminated.
However, you can set a timeout that breaks the running program after the specified number of milliseconds. Timeout is valid for each line after the TIMEOUT line, until the end or the next appearance of TIMEOUT keyword.

As a consequence, how to...

  • To make your script stable, add NEW to the beginning of the program list. Otherwise it will play different ways depending on the state of the runner when the script starts.
  • Writing a program from script is easy, just copy the list to the script text. The program lines go to the interactive command interpreter, which will recognize instructions and feed them into the runner.
  • Add a RUN keyword where you want to run the program.
  • Feeding INPUT instruction in the running program is easy, you can either use ENTER keyword or just put the input text on a line of the script, following the RUN line.
  • Feeding GET instruction goes with the BUFFER keyword, which needs to appear before the RUN line. Since the program won't stop with a blinking cursor when it hits the GET, the scripting engine stays idle then.
  • Use TIMEOUT scripting feature to keep your script running in case otherwise ever running programs.

Related

Wiki: Commands
Wiki: Home

Discussion

Anonymous
Anonymous

Add attachments
Cancel