Maths & Operators

From COD Modding & Mapping Wiki
Revision as of 19:53, 15 October 2008 by Zeroy (talk | contribs) (New page: == Maths & Operators == Image:Nutshell.png Maths is used throughout scripting to get several results, be it distance from two objects or simply to calculate a simple equation. For ex...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Maths & Operators

Maths is used throughout scripting to get several results, be it distance from two objects or simply to calculate a simple equation.

For example, a variable can be given data from an equation.

<variable> = 5 + 1;

The above example is pretty pointless, as you could just calculate it yourself and use the answer i.e.

<variable> = 6;

But variables can be calculated using other variables, for example...

<varAnswer> = <var1> + <var2>;

varAnswer will be equal to the value of var1 plus the value of var2.

There are several operators that can be used in maths...

+ :: Addition
- :: Subtraction
* :: Multiplication
/ :: Division
% :: Modulus
= :: Equals

There are also some more little-known operators such as...

++ :: Increment (+1)
-- :: Decrement (-1)
+= :: Incrementation (requires number)
-= :: Decrementation (requires number)

Example of these in use...

var++; // This is the same as var + 1
var--; // This the same as var - 1
var+=int; // This is the same as var + int (where int is a number)
var-=int; // This is the same as var - int (where int is a number)