A function is a special kind of a script. The common extension for function files is .sqf.

A function is much like a regular scripting command, except that you can use functions to create something like a custom command. A function does something and can then return a value to the point which 'called' that function or it can simply return Nothing.

Introduction

Usage

Functions should be used for any processes where the result or calculation done in the function is important. This result or calculation should be made in the least time possible. They are different to scripts, where timing is important.

Functions are running within the executing instance, which waits for the result of the function. Different to scripts, functions halt all other game engine processes until the function has completed its instructions. This means functions run faster than scripts, and the result of functions is immediate and unambiguous. It can also mean that if a function takes too long to run it will have an adverse effect on game play - large functions or CPU intensive functions can cause the game to seize up until it completes. When creating a functions you want the function to be short and sweet to achieve the best results.

Note: You can still use the special variables and commands of scripts in functions (Armed Assault only)!

Limitations

Functions have a limitation of 10,000 loops before they are forced to exit by the game engine in order to maintain some level of stability.

Return Value

The last value given in a function is returned to the calling instance. Note that there must not be a semicolon after this value.