home *** CD-ROM | disk | FTP | other *** search
/ Mega Score 72 / MSCD72.BIN / Demos / Colobot.exe / help / cbot / expr.txt < prev    next >
Encoding:
Text File  |  2001-07-02  |  1.7 KB  |  52 lines

  1. \b;Expressions
  2. Expressions can include the following operators: 
  3.  
  4. \c;+\n;  addition
  5. \c;-\n;  subtraction
  6. \c;*\n;  multiplication
  7. \c;/\n;  division
  8. \c;%\n;  remainder of the division (only for the type \c;\l;int\u cbot\int;\n;)
  9.  
  10. With the addition operator \c;+\n;, you can not only add numbers, you can also append \l;strings\u cbot\string;.
  11. \c;
  12. \s;    int    i = 12+3;      // returns 15
  13. \s;    string s = "a"+"bc";  // returns "abc"
  14. \s;    int    i = 2-5;       // returns -3
  15. \s;    float  f = 3.01*10;   // returns 30.1
  16. \s;    int    i = 5/3;       // returns 1
  17. \s;    float  f = 5/3;       // returns 1.67
  18. \s;    float  f = 5/0;       // returns an error
  19. \s;    int    i = 13%5;      // returns 3
  20. \s;    int    i = -8%3;      // returns -2
  21. \n;
  22. An expression can include constants or \l;variables\u cbot\var;. For example:
  23.  
  24. \s;\c;    12+dist\n;
  25.  
  26. Multiplications and divisions are performed before additions and subtractions. In order to be sure that the operations are performed in the right order, use brackets: 
  27. \c;
  28. \s;    12*a+b/c \n;is equivalent to\c; (12*a)+(b/c)
  29. \s;    2.5*(dist+range)
  30. \n;
  31. In order to improve readability, you can put as many spaces as you want: 
  32. \c;
  33. \s;    12*a + b/c
  34. \s;    2.5 * (dist+range)
  35. \n;
  36. Here is a list of mathematical functions: 
  37.  
  38. \c;sin(angle)    \n;sinus
  39. \c;cos(angle)    \n;cosinus
  40. \c;tan(angle)    \n;tangent
  41. \c;asin(value)   \n;arc-sinus
  42. \c;acos(value)   \n;arc-cosinus
  43. \c;atan(value)   \n;arc-tangente
  44. \c;sqrt(value)   \n;square root
  45. \c;pow(x, y)     \n;x power y
  46. \c;rand()        \n;random value ranging between 0 and 1
  47.  
  48. Angles are indicated in degrees.
  49.  
  50. \t;See also
  51. \l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
  52.