FANDOM


Introduction Edit

The function keyword is used to define a new console function or method. Unlike procedural language, functions are not declared in one place and defined in another, but defined only. Redeclaring a named function later in script over-rides the previous function. The format of a function takes one of two basic forms:

//function definition
function func_name( [arg0] , _ , [argn] )
{
statements;

[return val;]
}
  • func_name - Name by which this function will be subsequently called.
  • [arg0] , _ , [argn] - optional arguments.
  • statements - Any number of statements may be contained within the body of the function.
  • val - Functions may optionally return a value;
// console method definition
function namespace::func_name( %this, [arg0] , _ , [argn] )
{
statements;
[return val;]
}
  • namespace - The name of a datablock or object classname.
  •  :: - Namespace resolution operator
  •  %this - The first argument of a console method is [u]always[/u] the handle to the object which is calling the method.
// A simple function
function test ( %val )
{
echo( "test(" SPC %cal SPC ")" );

if( 10 = %val ) return true;

return false;
}

// A simple console method
function Item:test( %this , %val )
{
echo( "Item::test(" SPC %this SPC "," SPC %val SPC ")" );

if( 10 = %val  ) return true;

return false;
}

%obj = new Item()
{
// ..
};
%obj.test(10); //Normal method of calling
Item::test(%obj, 10); //Alternate method of calling

See Also Edit

Functions

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.