Function

From Game Editor

Revision as of 13:57, 26 November 2009 by Asmodeus (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to: navigation, search

User Functions

The Syntax for a User Function is:

<Return type>   <Function name>   (<Parameter list>){
     local definitions;
     statements;
     Return value;
}

Use the global code editor to make your own functions. Here is an example for a function:

void setText()
{
  strcpy(text, "Hello World!");
}

This functions make the Text to "Hello World!". Notice the use of the declaration Void. Use this when you don't need a returned value.

Sometimes you need a function that returns a number or a string. You can also use other Keywords such as Int or Double. Use the Keyword Return to return the result.

double numbersSum(double num1, double num2)
{
  return num1+num2;
}

Now you can use these codes in any scripts:

setText(); // set text to "Hello World"
x = numbersSum(x, y);

See Also