Documentation

Basics

Functions are separate pieces of code, that can increase readability and allow reusing code.
//Basic Function
Function()
{
    return 0; // Not needed.
}
That function doesn't do much, so let create a function that add two number together.
Sum(a, b) // Accepts 2 arguments
{
    return (a+b);
}

Advance

Tagged Argument

Arguments can be tagged to enhanced compile checks.

Variable Arguments

A function that takes a variable number of arguments, uses the "ellipsis" operator("...") in the function header to denote the position of the first variable argument. The function can access the arguments with the functions numargs, getarg and setarg

Passing Arrays

Passed by reference

Lets start of with a simple script
main()
{
    new testa = 10;
    TestFunction();
    DebugText("Testa = %d", testa); // 'testa' will be equal to 10
}

TestFunction(blank = 44, &test = 0)
{
    test += 15;
    DebugText("Blank = %d", blank);
}
We have a function called 'TestFunction', which has 2 arguments, 'blank' & 'testa'. You should have read in Basic section that both arguments have default value, but you wondering what '&' in front of 'testa'. The '&' allow the function to call by reference instead of call by value. What does mean, well it allows function to change the reference variable.
Lets see how that works by replace 'TestFunction();' with 'TestFunction( _, testa);'.
main()
{
    new testa = 10;
    TestFunction( _, testa); // We changed this line
    DebugText("Testa = %d", testa); // 'testa' should now equal to 25
}

You should notice that Testa now equals 25 when it displayed on-screen. Please note: Arrays are always passed by reference.You may have notice that we passed '_' for the 'blank' argument, well that the placeholder for the default value.

Positional arguments
In the previous topic, we mention that '_' is a placeholder for the arguments default value. We could have also have use positional arguments, this allow us to set arguments in any order. To do this, we have '.' followed by the name of the function argument.
Example:
TestFunction(.test = testa);

Comments

Comming Soon