Difference between revisions of "Optional Arguments"

From Multi Theft Auto: Wiki
Jump to: navigation, search
m
Line 5: Line 5:
 
Example:
 
Example:
  
<syntaxhighlight lang="lua">theVehicle = createVehicle ( int model, float x, float y, float z, [ float rx, float ry, float rz ] )</syntaxhighlight>
+
<syntaxhighlight lang="lua">createVehicle ( int model, float x, float y, float z, [ float rx, float ry, float rz ] )</syntaxhighlight>
  
 
In this example, '''rx''', '''ry''', and '''rz''' are [[Optional Arguments]].
 
In this example, '''rx''', '''ry''', and '''rz''' are [[Optional Arguments]].

Revision as of 01:37, 12 August 2010

Optional Arguments are arguments that are passed to a function but are not required for the function to run. Often, if you do not specify them, default values will be used instead.

When looking at the Syntax for an argument, Optional arguments are always enclosed in Square brackets.

Example:

createVehicle ( int model, float x, float y, float z, [ float rx, float ry, float rz ] )

In this example, rx, ry, and rz are Optional Arguments.

Using Optional Arguments

Optional Arguments have one limitation. You cannot use any optional arguments unless all previous arguments are also supplied.

This means that in the previous example, if you wanted to supply rz, you would also need to supply rx, and ry in order.