Maths & Operators: Difference between revisions

From COD Modding & Mapping Wiki
Jump to navigation Jump to search
(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...)
 
No edit summary
Line 1: Line 1:
== 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.
== [[Maths & Operators]] ==
 
[[Image:Nutshell.png]] Maths is used throughout scripting to get many different values, be it the distance between two objects or to calculate an equation.


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


  <variable> = 5 + 1;
  variable = 5 + 1;


The above example is pretty pointless, as you could just calculate it yourself and use the answer i.e.
Although the above example is pretty pointless, as it adds one constant to another to make a constant, and you can just calculate it yourself and use the answer i.e.


  <variable> = 6;
  variable = 6;


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


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


varAnswer will be equal to the value of var1 plus the value of var2.
varAnswer will be equal to the value of var1 plus the value of var2.
Line 34: Line 35:
</pre>
</pre>
Example of these in use...
Example of these in use...
 
<pre>
  var++; // This is the same as var + 1
  var++; //Set var to var + 1
  var--; // This the same as var - 1
  var--; //Set var to var - 1
  var+=int; // This is the same as var + int (where int is a number)
  var += int; //Set var to var + int
  var-=int; // This is the same as var - int (where int is a number)
  var -= int; //Set var to var - int
</pre>

Revision as of 02:38, 24 October 2008

Maths & Operators

Maths is used throughout scripting to get many different values, be it the distance between two objects or to calculate an equation.

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

variable = 5 + 1;

Although the above example is pretty pointless, as it adds one constant to another to make a constant, and you can 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++; //Set var to var + 1
 var--; //Set var to var - 1
 var += int; //Set var to var + int
 var -= int; //Set var to var - int