Function Declarations

To declare a function, specify a return type, name, parameter list, optional attribute list, and function body. In Scenome Scripting Language, a function cannot be declared without also being defined immediately thereafter.

Details

Details are as follows:

Examples

The following example declares a function named ComputeSum, which sums two values and returns the result.

function int ComputeSum( int value1, int value2 )
{
   return value1 + value2;
}

The following example declares a function named FormatQuadrantName, which appends two integer values to a string, and returns the result. For Example: "Quadrant 1x2"

function string FormatQuadrantName( string prefix, int quadx, int quady )
{
   return prefix + " " + quadx + "x" + quady;
}

The following example declares a function named GetDistance, which calculates the distance between two points.

function double GetDistance( double x1, double y1, double x2, double y2 )
{
   double dx = x1 - x2;
   double dy = y1 - y2;
   return Math.Sqrt( dx * dx + dy * dy );
}

Reference parameters are typically used with functions that require more than one output. The following example declares a function named TranslateXY, which translates the first two parameters passed to it by the amount specified in the third parameter. REF parameters cannot cross library boundaries.

function void TranslateXY( ref int x, ref int y, int delta )
{
   x = x + delta;
   y = y + delta;
}