BadScript

Function

Contains a Function that can be executed.

function f()
{
	//Do Stuff
}

global-Modifier

Functions that have the global modifier are made available at all scopes

global function f()
{
	//Do Stuff
}

Lambda Functions

Functions that only contain a single line, can be written in the => format.

function f(x) => return x * x

Anonymous Functions

Functions can be declared without specifing a name. Anonymous functions can not be global

f = function(x)
{
	return x * x
}
f = function(x) => return x * x

Parameters

Functions can have a variable amount of parameters. Parameters are only valid inside the declaring function.

function f(x)
{
	//Do Stuff with x
}

Null Checked Parameters

If a parameter is prefixed with ! in the function signature, the Script Engine is guaranteeing that the function can not be invoked with that parameter beeing null

function(!x)
{
	//Do Stuff with x
}

f(1)
f("AAA")
f(null) //Crash

Optional Parameters

If a parameter is prefixed with ? the function can be invoked without specifying the parameter. If the parameter is not specified, the parameter will contain null.

function f(?x)
{
	if(x == null)
	{
		//Do Stuff without x
	}
	else
	{
		//Do Stuff with x
	}
}

f()
f(2)

Array Parameters

If a function is defined with a single parameter which is prefixed with *, the Script Engine will pass an array of the arguments to the function, which makes the function accept all numbers of parameters.

function f(*args)
{
	foreach arg in args
	{
		//Do Stuff with Argument
	}
}

f(1, "Hello World")
f(true)
f()

Returning Values

When functions return values, the function needs to return a value in every possible execution path.

function f() //Legal
{
	return "Hello World"
}

function f(x) //Legal
{
	if(x == true)
	{
		return "Hello World"
	}

	return null
}

function f(x) //Legal
{
	if(x == true)
	{
		return "Hello World"
	}
	else
	{
		return null
	}
}

function f(x) //Illegal
{
	if(x == true)
	{
		return "Hello World"
	}

	//Not all Code Paths return a value
}

Default Operators

Implemented Functions

Invoke

Invokes the Function

function f(x)
{
	return x * 2
}

v = 1
vDouble = f.Invoke([v], true) 		//[v] = Defining an Array with one element(v)
									//true = Execute Hooks

vQuadruple = f.Invoke([vDouble]) 	//[v] = Defining an Array with one element(v)

Required Parameters

Optional Parameters

Hook

Hooks into a function. Every time this function gets invoked, all registered hooks are called.

function f(x)
{
	return x * x
}

function NotifyIfInvoked(x)
{
	//Do Stuff
}

f.Hook(NotifyIfInvoked) // Hooks NotifyIfInvoked into f

f(2) 					// NotifyIfInvoked gets called before f
function f(x)
{
	return x * x
}

function InterceptIfInvoked(x)
{
	return x * x * x	// Returning anything else than null will abort the invocation
						// of all following hooks and the base function itself
}

f.Hook(InterceptIfInvoked) //Hooks InterceptIfInvoked into f

f(2) 					// InterceptIfInvoked gets called before f. The return is 8
f.Invoke([2], false) 	// InterceptIfInvoked does not get called. The return is 4

Required Parameters

ReleaseHook

Releases the Specified hook from the function

function f() {}
function f_hook() {}

f.Hook(f_hook)
f() // Calls f_hook
f.ReleaseHook(f_hook)
f() // Does not call f_hook anymore

Required Parameters

ReleaseHooks

Releases all hooks from the function

function f() {}
function f_hook1() {}
function f_hook2() {}
f.Hook(f_hook1)
f.Hook(f_hook2)

f.ReleaseHooks() //Clears all Hooks

List of all Built-In Types