Notch Notch Manual 0.9.23
 Light | Dark
Anatomy of a JS script

Anatomy of a JS script

A typical Notch JS script can have these types of components:

Component Description
Global variables These can be used for passing values in and out of the JavaScript node. You define the input and output global variables you want to hook in the JavaScript Node. You can have non hooked global variables as well.
Init() function called by Notch on initialisation of the script.
Update() function called by Notch every frame.
OnKeyPress() function called by Notch when a key is pressed.

All these elements are optional and not required in a script.

Notch will run the script when it loads, so you can initialize elements when you first start.

var inputA, inputB, outputA, outputB;

function Init() 
{ 
    Log("My Script v0.1");
    // Initialize any *internal* variables here.
}

function Update() 
{ 
    // Put your active code in here.       
}

function OnKeyPress(key)
{
    // Respond to keypresses here
}
Copy JS

However, your JavaScript might be as light as:

var inputA, inputB, outputA;

function Update()
{
    outputA = inputA + inputB;
}
Copy JS