Hosting and domain costs until October 2024 have been generously sponsored by dumptruck_ds. Thank you!

QuakeC Definition of Functions

From Quake Wiki

Revision as of 19:36, 7 May 2008 by ShoTro (talk | contribs) (New page: === Definition of Functions === == Ordinary functions == The general structure of a function definition is: type (type param1, typeparam2, ... ) function = { ... code ....)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Definition of Functions

Ordinary functions

The general structure of a function definition is:

   type (type param1, typeparam2, ... ) function =
   {
      ... code ...
      return expression;
   };

Notes:

   * Do not forget the ; after the ending brackets.
   * The return statement can be used more than once, anywhere in the function.
   * The expresion in a return statement must of course be of the same type as the return value of the fuction.
   * If the return type is void, then you can omit the return statement. 

Here are some examples:

   void ()	think = {...};
   entity ()	FindTarget = {...};
   void(vector destination, float speed, void() callback)  SUB_CalcMove = {...};


Function calls

Here is how a function is called in Quake-C:

   function_name ( parameter1, parameter2,... )

The cannot be more than 8 parameters.


Function declaration

If you want to use a function before defining it, you must declare it, otherwise the Quake-C compiler will not be able to use it.

The general structure of a function declaration is:

   type (type param1, typeparam2, ... ) function;


Definition of a frame function

Frame functions (also called States) are special functions that are meant to facilitate the definition of models animation frames.

Here is an example:

   void() framename = [$framenum, nextthink] { ...code...};

It is strictly equivalent to:

   void() framename =
   {
      self.frame= $framenum;  // the model frame to displayed
      self.nextthink = time + 0.1;   // next frame happens in 1/10 of second
      self.think = nextthink; // the function to call at the next frame
      ...code...
   };