//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); }
Arguments can be tagged to enhanced compile checks.
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
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.
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 argumentsTestFunction(.test = testa);
Comming Soon