parent
0c3a41c43b
commit
b0280f5a40
|
@ -0,0 +1,7 @@
|
||||||
|
Development team: Beta tester core team:
|
||||||
|
|
||||||
|
- Daniel Roux - Adrien Roux - Michael Jubin
|
||||||
|
- Denis Dumoulin - Didier Raboud - Daniel Sauthier
|
||||||
|
- Otto Kölbl - Nicolas Beuchat - Nicolas Stubi
|
||||||
|
- Michael Walz - Joël Roux - Patrick Thévoz
|
||||||
|
- Didier Gertsch
|
|
@ -0,0 +1,91 @@
|
||||||
|
\b;Programming - the CBOT language
|
||||||
|
The CBOT language is very close in structure and syntax to C++ and Java. It has been adapted for the specific purposes of COLOBOT, and for an efficient pedagogical approach.
|
||||||
|
This language is made up of instructions (see below), \l;blocks\u cbot\bloc;, \l;functions\u cbot\function;, \l;classes\u cbot\class;, \l;variables\u cbot\var;, \l;arrays\u cbot\array;, \l;expressions\u cbot\expr; and \l;conditions\u cbot\cond;.
|
||||||
|
|
||||||
|
o \c;\token;Instructions\norm;\n;
|
||||||
|
In the program editor, an instruction in the CBOT language is always displayed on an orange background. If an instruction hasn't got an orange background, this means that it has been misspelled. Instruction names are always written in lower case.
|
||||||
|
|
||||||
|
o \c;\type;Type\norm;\n;
|
||||||
|
The \l;type\u cbot\type; of a variable appears with a green background.
|
||||||
|
|
||||||
|
o \c;\const;Constants\norm;\n;
|
||||||
|
Constants like \l;categories\u cbot\category; are displayed with a red background.
|
||||||
|
|
||||||
|
\t;Instructions in the CBOT language:
|
||||||
|
\c;\l;extern\u cbot\extern; \n;Indicate the main function
|
||||||
|
\c;\l;if\u cbot\if; \n;Choice structure
|
||||||
|
\c;\l;else\u cbot\if; \n;Alternative choice structure
|
||||||
|
\c;\l;for\u cbot\for; \n;Loop structure
|
||||||
|
\c;\l;while\u cbot\while; \n;Control structure
|
||||||
|
\c;\l;do\u cbot\do; \n;Control structure
|
||||||
|
\c;\l;break\u cbot\break; \n;Exit from a loop
|
||||||
|
\c;\l;continue\u cbot\continue; \n;Continues the loop
|
||||||
|
\c;\l;return\u cbot\return; \n;Exit from a function
|
||||||
|
\c;\l;sizeof\u cbot\sizeof; \n;Size of an array
|
||||||
|
|
||||||
|
\t;Specific instructions for bots:
|
||||||
|
\c;\l;radar\u cbot\radar; \n;Object detection
|
||||||
|
\c;\l;direction\u cbot\direct; \n;Calculates a rotation angle
|
||||||
|
\c;\l;distance\u cbot\dist; \n;Calculates a distance
|
||||||
|
\c;\l;distance2d\u cbot\dist2d; \n;Calculates a distance
|
||||||
|
\c;\l;wait\u cbot\wait; \n;Waits
|
||||||
|
\c;\l;move\u cbot\move; \n;Moves forward or backward
|
||||||
|
\c;\l;turn\u cbot\turn; \n;Turns
|
||||||
|
\c;\l;goto\u cbot\goto; \n;Goes to a given position
|
||||||
|
\c;\l;motor\u cbot\motor; \n;Direct motor control
|
||||||
|
\c;\l;jet\u cbot\jet; \n;Direct jet engine control
|
||||||
|
\c;\l;message\u cbot\message; \n;Displays a message
|
||||||
|
\c;\l;retobject\u cbot\retobj; \n;Returns an object from a function
|
||||||
|
\c;\l;errmode\u cbot\errmode; \n;Error treatement control
|
||||||
|
\c;\l;abstime\u cbot\abstime; \n;Returns the absolute time
|
||||||
|
|
||||||
|
\t;Instructions about topology:
|
||||||
|
\c;\l;space\u cbot\space; \n;Calculates a free space
|
||||||
|
\c;\l;topo\u cbot\topo; \n;Returns the altitude of a point
|
||||||
|
\c;\l;flatground\u cbot\flatgrnd; \n;Returns radius of a flat area
|
||||||
|
|
||||||
|
\t;Instructions specific to some bots:
|
||||||
|
\c;\l;grab\u cbot\grab; \n;Picks up an object
|
||||||
|
\c;\l;drop\u cbot\drop; \n;Puts down an object
|
||||||
|
\c;\l;sniff\u cbot\sniff; \n;Sounds the subsoil
|
||||||
|
\c;\l;thump\u cbot\thump; \n;Overturns alien insects
|
||||||
|
\c;\l;recycle\u cbot\recycle; \n;Recycles a derelict bot
|
||||||
|
\c;\l;shield\u cbot\shield; \n;Extends or withdraws the shield
|
||||||
|
\c;\l;fire\u cbot\fire; \n;Fires the cannon
|
||||||
|
\c;\l;aim\u cbot\aim; \n;Vertical angle of the cannon
|
||||||
|
|
||||||
|
\t;Specific instructions for exchange posts:
|
||||||
|
\c;\l;receive\u cbot\receive; \n;Receives an information
|
||||||
|
\c;\l;send\u cbot\send; \n;Sends a new information
|
||||||
|
\c;\l;testinfo\u cbot\testinfo; \n;Tests if an information exists
|
||||||
|
\c;\l;deleteinfo\u cbot\delinfo; \n;Deletes an existing information
|
||||||
|
|
||||||
|
\t;Specific instructions for classes:
|
||||||
|
\c;\l;class\u cbot\class; \n;Class declararion
|
||||||
|
\c;\l;public\u cbot\public; \n;Declares a public function
|
||||||
|
\c;\l;private\u cbot\private; \n;Declares a private class member
|
||||||
|
\c;\l;static\u cbot\static; \n;Declares a static class member
|
||||||
|
\c;\l;synchronized\u cbot\synchro; \n;Prevents simultaneous execution
|
||||||
|
\c;\l;new\u cbot\new; \n;Creates a new instance
|
||||||
|
\c;\l;this\u cbot\this; \n;Reference to the current instance
|
||||||
|
|
||||||
|
\t;Specific instructions for strings:
|
||||||
|
\c;\l;strlen\u cbot\strlen; \n;Gets string length
|
||||||
|
\c;\l;strleft\u cbot\strleft; \n;Extracts left part
|
||||||
|
\c;\l;strright\u cbot\strright; \n;Extracts right part
|
||||||
|
\c;\l;strmid\u cbot\strmid; \n;Extracts center part
|
||||||
|
\c;\l;strfind\u cbot\strfind; \n;Finds a substring.
|
||||||
|
\c;\l;strval\u cbot\strval; \n;Converts string to number
|
||||||
|
\c;\l;strupper\u cbot\strupper; \n;Converts to upper case
|
||||||
|
\c;\l;strlower\u cbot\strlower; \n;Converts to lower case
|
||||||
|
|
||||||
|
\t;Specific instructions for files:
|
||||||
|
\c;\l;open\u cbot\open; \n;Opens a file
|
||||||
|
\c;\l;close\u cbot\close; \n;Closes a file
|
||||||
|
\c;\l;writeln\u cbot\writeln; \n;Writes line to a file
|
||||||
|
\c;\l;readln\u cbot\readln; \n;Reads line from a file
|
||||||
|
\c;\l;eof\u cbot\eof; \n;Tests if end of file
|
||||||
|
\c;\l;deletefile\u cbot\deletef; \n;Deletes a file
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,11 @@
|
||||||
|
\b;Instruction \c;abstime\n;
|
||||||
|
Syntax¦:
|
||||||
|
\s;\c;abstime ( );\n;
|
||||||
|
|
||||||
|
Return the time in seconds elapsed since the beginning of the mission.
|
||||||
|
|
||||||
|
\t;Return: \c;\l;float\u cbot\float;\n;
|
||||||
|
Time in seconds.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,21 @@
|
||||||
|
\b;Instruction \c;aim\n;
|
||||||
|
Syntax :
|
||||||
|
\s;\c;aim ( angle );\n;
|
||||||
|
|
||||||
|
This instruction sets the vertical angle of the cannon. The following robots are equipped with a cannon:
|
||||||
|
o \l;Shooter\u object\botfr;
|
||||||
|
o \l;Orga shooter\u object\botor;
|
||||||
|
o \l;Phazer shooter\u object\botphaz;
|
||||||
|
|
||||||
|
When controlling the robot through programming, the only way to turn the gun left or right is to turn the whole robot with the instruction \c;\l;turn\u cbot\turn;\n;.
|
||||||
|
|
||||||
|
\t;angle: \c;\l;float\u cbot\float;\n;
|
||||||
|
Angle in degrees of the gun relative to the robot. A positive value orients the gun upward. For shooters and orga shooters, the angle must range from \c;-20\n; to \c;+20\n; degrees. For phazer shooters, the angle must range from \c;-20\n; to \c;45\n; degrees.
|
||||||
|
|
||||||
|
\t;Return value: \c;\l;int\u cbot\int;\n;
|
||||||
|
Zero if everything is OK, a value different from zero if the rotation could not be performed:
|
||||||
|
\c;== 0 \n;The gun has now got the desired orientation
|
||||||
|
\c;!= 0 \n;rotation impossible
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,31 @@
|
||||||
|
\b;Arrays
|
||||||
|
An array is basically a collection of variables of the same type or class. You can use N dimensionnal arrays in the CBOT language. Each dimension is limited to 9999 elements. You must use square brackets \c;[]\n; after the type name or the variable name to declare an array.
|
||||||
|
\c;
|
||||||
|
\s;int [ ] a; // an array of int
|
||||||
|
\s;int a [12]; // an array of int limited to 12 elements
|
||||||
|
\s;string s[3]; // an array of 3 strings
|
||||||
|
\s;float xy[][]; // an 2 dimensionnal array of floats
|
||||||
|
\n;
|
||||||
|
Actually when the CBOT interpreter encounters an array declaration, it just creates a \c;\l;null\u cbot\null;\n; \l;reference\u cbot\pointer;:
|
||||||
|
\c;
|
||||||
|
\s;int a[5]; // a is now a null reference
|
||||||
|
\n;
|
||||||
|
As soon as you put values into the array, the elements are created and the reference is initialized:
|
||||||
|
\c;
|
||||||
|
\s;a[2] = 213; // a points to
|
||||||
|
\s; // 3 élements [0], [1] et [2]
|
||||||
|
\n;
|
||||||
|
After this operation, \c;a\n; contains a reference to the elements of the array. Elements \c;[0]\n; and \c;[1]\n; are created but not initialized because an array cannot contain empty elements. The \c;\l;sizeof\u cbot\sizeof;\n; instruction allows you to obtain the number of elements contained in an array.
|
||||||
|
|
||||||
|
When an array is declared with a maximum size, the program will stop as soon as there is an access beyond the maximum array size. No error is signalled during compilation even if the error is obvious:
|
||||||
|
\c;
|
||||||
|
\s;{
|
||||||
|
\s; int a[5];
|
||||||
|
\s; a[7] = 123; // no error at compile time
|
||||||
|
\s; // but error at run time
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
If you pass an array as parameter to a \l;function\u cbot\function;, the function only receives a \l;reference\u cbot\pointer; to the array. That means if you modify an array element in the function, the element of the array that has been passed the function will be actuallay modified.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,49 @@
|
||||||
|
\b;Blocks
|
||||||
|
You can use braces \c;{ }\n; to group a number of instructions together in order to make one single block out of them, for example:
|
||||||
|
\c;
|
||||||
|
\s; {
|
||||||
|
\s; float t;
|
||||||
|
\s; t = a;
|
||||||
|
\s; a = b;
|
||||||
|
\s; b = t; // switches round a and b
|
||||||
|
\s; }
|
||||||
|
\n;
|
||||||
|
Every instruction in the block is followed by a \l;semicolon\u cbot\term;, but the block itself is not.
|
||||||
|
Let us take the following example with the instruction \c;\l;if\u cbot\if;\n; to illustrate the use of blocks in a program:
|
||||||
|
\c;
|
||||||
|
\s; if ( a < b )
|
||||||
|
\s; \n;instruction 1\c;;
|
||||||
|
\s; \n;instruction 2\c;;
|
||||||
|
\s; \n;instruction 3\c;;
|
||||||
|
\n;
|
||||||
|
If the \l;condition\u cbot\cond; is true, instructions 1, 2 and 3 are performed. If the condition is false, only instruction 1 is ignored, instructions 2 and 3 are performed. The fact that instruction 2 is lined up with instruction 1 does not matter.
|
||||||
|
If you want to perform instructions 1 and 2 only if the condition is true, you have to bracket them together in a block:
|
||||||
|
\c;
|
||||||
|
\s; if ( a < b )
|
||||||
|
\s; {
|
||||||
|
\s; \n;instruction 1\c;;
|
||||||
|
\s; \n;instruction 2\c;;
|
||||||
|
\s; }
|
||||||
|
\s; \n;instruction 3\c;;
|
||||||
|
\n;
|
||||||
|
Blocks may be needed with instructions \c;\l;if\u cbot\if;\n;, \c;\l;while\u cbot\while;\n; and \c;\l;for\u cbot\for;\n;, in order to group several instructions that should be performed only if a condition is true, or repeated several times.
|
||||||
|
You can fit blocks into other blocks, on as many levels as you need. Here is an example of imbrication on two levels :
|
||||||
|
\c;
|
||||||
|
\s; if ( a > b )
|
||||||
|
\s; {
|
||||||
|
\s; int i = 0;
|
||||||
|
\s; while ( i < 18 )
|
||||||
|
\s; {
|
||||||
|
\s; move(10);
|
||||||
|
\s; turn(5);
|
||||||
|
\s; i = i+1;
|
||||||
|
\s; }
|
||||||
|
\s; }
|
||||||
|
\n;
|
||||||
|
You had better line up the open brace \c;{\n; with the closing brace \c;}\n; in order to improve readability, but it is not compulsory. The following example takes less space, is equivalent to the previous example, but it is not advisable to write your programs in the following style :
|
||||||
|
\c;
|
||||||
|
\s; if(a>b) { int i=0; while(i<18) {
|
||||||
|
\s; move(10);turn(5);i=i+1; }}
|
||||||
|
\n;
|
||||||
|
\t;See also
|
||||||
|
\l;Instructions\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,5 @@
|
||||||
|
\b;Type \c;bool\n;
|
||||||
|
In a variable of this type you can put a boolean value, that is a value that can take only two states: true or false.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,25 @@
|
||||||
|
\b;Instruction \c;break\n;
|
||||||
|
Syntax :
|
||||||
|
\s;\c;while ( condition )
|
||||||
|
\s;{
|
||||||
|
\s; break;
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
With this instruction, you can get out immediately of a \c;\l;while\u cbot\while;\n; or \c;\l;for\u cbot\for;\n; loop.
|
||||||
|
|
||||||
|
Here is an example:
|
||||||
|
\s;\c;int i = 0;
|
||||||
|
\s;while ( true )
|
||||||
|
\s;{
|
||||||
|
\s; \n;Instructions ...\c;
|
||||||
|
\s; i = i+1;
|
||||||
|
\s; if ( i >= 10 )
|
||||||
|
\s; {
|
||||||
|
\s; break;
|
||||||
|
\s; }
|
||||||
|
\s; \n;more instructions ...\c;
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,108 @@
|
||||||
|
\b;Value \c;Categories\n;
|
||||||
|
Categories represent the names of objects in the CBOT language. Everything in COLOBOT is an object: robots, buildings, raw materials, etc., even yourself.
|
||||||
|
|
||||||
|
In a program, categories are always displayed on a \const;red background\norm;. If a category isn't highlighted in red, it is misspelled. Caps and lower cases should be kept as is.
|
||||||
|
|
||||||
|
Below are the different categories available :
|
||||||
|
|
||||||
|
\t;Buildings :
|
||||||
|
|
||||||
|
\button 176; \c;\l;Houston\u object\Huston; \n;Mission Control
|
||||||
|
\button 171; \c;\l;SpaceShip\u object\base; \n;Spaceship
|
||||||
|
\button 160; \c;\l;BotFactory\u object\factory; \n;Robot Factory
|
||||||
|
\button 163; \c;\l;ResearchCenter\u object\research; \n;Research Center
|
||||||
|
\button 168; \c;\l;RadarStation\u object\radar; \n;Radar
|
||||||
|
\button 172; \c;\l;ExchangePost\u object\exchange; \n;Information Exchange Post
|
||||||
|
\button 169; \c;\l;RepairCenter\u object\repair; \n;Repair Center
|
||||||
|
\button 165; \c;\l;DefenseTower\u object\tower; \n;Defense Tower
|
||||||
|
\button 166; \c;\l;AutoLab\u object\labo; \n;Organic Matter Analyzer
|
||||||
|
\button 164; \c;\l;PowerStation\u object\station; \n;Power Station
|
||||||
|
\button 167; \c;\l;PowerPlant\u object\energy; \n;Power Cell Factory
|
||||||
|
\button 170; \c;\l;NuclearPlant\u object\nuclear; \n;Nuclear Plant
|
||||||
|
\button 162; \c;\l;Converter\u object\convert; \n;Titanium Converter
|
||||||
|
\button 161; \c;\l;Derrick\u object\derrick; \n;Derrick
|
||||||
|
\button 174; \c;\l;PowerCaptor\u object\captor; \n;Parabolic Lightning Conductor
|
||||||
|
\button 175; \c;\l;Vault\u object\safe; \n;Vault
|
||||||
|
\c;\l;StartArea\u object\start; \n;Starting Pad
|
||||||
|
\c;\l;GoalArea\u object\goal; \n;Finishing Pad
|
||||||
|
\c;\l;AlienNest\u object\nest; \n;Alien Nest
|
||||||
|
|
||||||
|
|
||||||
|
\t;Portable Objects :
|
||||||
|
|
||||||
|
\c;\l;TitaniumOre\u object\titanore; \n;Titanium Ore
|
||||||
|
\c;\l;UraniumOre\u object\uranore; \n;Uranium Ore
|
||||||
|
\c;\l;Titanium\u object\titan; \n;Cube of converted Titanium
|
||||||
|
\c;\l;PowerCell\u object\power; \n;Regular Power Cell
|
||||||
|
\c;\l;NuclearCell\u object\atomic; \n;Nuclear Power Cell
|
||||||
|
\c;\l;OrgaMatter\u object\bullet; \n;Organic Matter
|
||||||
|
\c;\l;BlackBox\u object\bbox; \n;Black Box
|
||||||
|
\c;\l;TNT\u object\tnt; \n;Explosive device
|
||||||
|
\c;\l;KeyA..D\u object\key; \n;Keys A, B, C and D
|
||||||
|
|
||||||
|
|
||||||
|
\t;Robots :
|
||||||
|
|
||||||
|
\button 158; \c;\l;PracticeBot\u object\bottr; \n;Practice Bot
|
||||||
|
\button 173; \c;\l;TargetBot\u object\bottarg; \n;Target Bot
|
||||||
|
|
||||||
|
\button 137; \c;\l;WheeledGrabber\u object\botgr; \n;Wheeled Grabber
|
||||||
|
\button 138; \c;\l;TrackedGrabber\u object\botgc; \n;Tracked Grabber
|
||||||
|
\button 139; \c;\l;WingedGrabber\u object\botgj; \n;Winged Grabber
|
||||||
|
\button 150; \c;\l;LeggedGrabber\u object\botgs; \n;Legged Grabber
|
||||||
|
|
||||||
|
\button 140; \c;\l;WheeledSniffer\u object\botsr; \n;Wheeled Sniffer
|
||||||
|
\button 141; \c;\l;TrackedSniffer\u object\botsc; \n;Tracked Sniffer
|
||||||
|
\button 142; \c;\l;WingedSniffer\u object\botsj; \n;Winged Sniffer
|
||||||
|
\button 152; \c;\l;LeggedSniffer\u object\botss; \n;Legged Sniffer
|
||||||
|
|
||||||
|
\button 143; \c;\l;WheeledShooter\u object\botfr; \n;Wheeled Shooter
|
||||||
|
\button 144; \c;\l;TrackedShooter\u object\botfc; \n;Tracked Shooter
|
||||||
|
\button 145; \c;\l;WingedShooter\u object\botfj; \n;Winged Shooter
|
||||||
|
\button 151; \c;\l;LeggedShooter\u object\botfs; \n;Legged Shooter
|
||||||
|
|
||||||
|
\button 153; \c;\l;WheeledOrgaShooter\u object\botor; \n;Wheeled Orga Shooter
|
||||||
|
\button 154; \c;\l;TrackedOrgaShooter\u object\botoc; \n;Tracked Orga Shooter
|
||||||
|
\button 155; \c;\l;WingedOrgaShooter\u object\botoj; \n;Winged Orga Shooter
|
||||||
|
\button 156; \c;\l;LeggedOrgaShooter\u object\botos; \n;Legged Orga Shooter
|
||||||
|
|
||||||
|
\button 149; \c;\l;Subber\u object\botsub; \n;Subber
|
||||||
|
\button 148; \c;\l;Recycler\u object\botrecy; \n;Recycler
|
||||||
|
\button 157; \c;\l;Shielder\u object\botshld; \n;Shielder
|
||||||
|
\button 146; \c;\l;Thumper\u object\bottump; \n;Thumper
|
||||||
|
\button 147; \c;\l;PhazerShooter\u object\botphaz; \n;Phazer Shooter
|
||||||
|
|
||||||
|
|
||||||
|
\t;Enemies :
|
||||||
|
|
||||||
|
\c;\l;AlienQueen\u object\mother; \n;Alien Queen
|
||||||
|
\c;\l;AlienEgg\u object\egg; \n;Alien Egg
|
||||||
|
\c;\l;AlienAnt\u object\ant; \n;Ant
|
||||||
|
\c;\l;AlienSpider\u object\spider; \n;Spider
|
||||||
|
\c;\l;AlienWasp\u object\wasp; \n;Wasp
|
||||||
|
\c;\l;AlienWorm\u object\worm; \n;Worm
|
||||||
|
|
||||||
|
|
||||||
|
\t;Miscellaneous :
|
||||||
|
|
||||||
|
\button 136; \c;\l;Me\u object\human; \n;You!
|
||||||
|
\c;\l;Mine\u object\mine; \n;Mine
|
||||||
|
\c;\l;Barrier\u object\barrier; \n;Barrier
|
||||||
|
\c;\l;Wreck\u object\wreck; \n;Derelict bot
|
||||||
|
\c;\l;Ruin\u object\ruin; \n;Derelict building
|
||||||
|
|
||||||
|
|
||||||
|
\t;Flags and Other Indicators :
|
||||||
|
|
||||||
|
\c;\l;BlueFlag\u object\flag; \n;Blue Flag
|
||||||
|
\c;\l;RedFlag\u object\flag; \n;Red Flag
|
||||||
|
\c;\l;GreenFlag\u object\flag; \n;Green Flag
|
||||||
|
\c;\l;YellowFlag\u object\flag; \n;Yellow Flag
|
||||||
|
\c;\l;VioletFlag\u object\flag; \n;Violet Flag
|
||||||
|
\c;\l;WayPoint\u object\waypoint; \n;Checkpoint
|
||||||
|
\c;\l;EnergySite\u object\enerspot; \n;Underground Energy Deposit
|
||||||
|
\c;\l;TitaniumSite\u object\stonspot; \n;Underground Titanium Deposit
|
||||||
|
\c;\l;UraniumSite\u object\uranspot; \n;Underground Uranium Deposit
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;CBOT Language\u cbot; and \l;Variables\u cbot\type;.
|
|
@ -0,0 +1,72 @@
|
||||||
|
\b;Instruction \c;class\n;
|
||||||
|
This allows you to declare a class definition using following syntax:
|
||||||
|
\c;
|
||||||
|
\s;public class ClassName
|
||||||
|
\s;{
|
||||||
|
\s; declarations;
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
Classes can only be \l;public\u cbot\public;, that is they can be used from all bots in a mission. Class members are also public, that is they are accessible from outside the class. Class members can be fields or functions (also called methods), for example the followin class \c;MyClass\n; contains 4 fields (a, b, x and s) and one method (MyFunction).
|
||||||
|
\c;
|
||||||
|
\s;public class MyClass
|
||||||
|
\s;{
|
||||||
|
\s; int a, b;
|
||||||
|
\s; float x = 3.33;
|
||||||
|
\s; string s = "hello";
|
||||||
|
\s; float MyFunction( float value )
|
||||||
|
\s; {
|
||||||
|
\s; return (value*x)-1;
|
||||||
|
\s; }
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
As shown in this exemple the class members can be initialized (\c;x=3.33\n;). You can also define a constructor which is a special method having the same name as the class name. This method will be called automatically at creation time of a class instance. You can also declare more than one method with the same name but different parameters.
|
||||||
|
\c;
|
||||||
|
\s;public class MyClass
|
||||||
|
\s;{
|
||||||
|
\s; int a, b;
|
||||||
|
\s; void MyClass( )
|
||||||
|
\s; {
|
||||||
|
\s; a = 2; b = 3;
|
||||||
|
\s; }
|
||||||
|
\s; void MyClass( int a, int b )
|
||||||
|
\s; {
|
||||||
|
\s; this.a = a; this.b = b;
|
||||||
|
\s; }
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
In this example two constructors are declared for \c;MyClass\n;, one without parameters and the other one with two parameters. As the names of the parameters of the second constructor are the same as the names of the two members \c;a\n; et \c;b\n; we must use the \c;\l;this\u cbot\this;.a\n; and \c;\l;this\u cbot\this;.b\n; to avoid confusion with the parameters. Another more simpler solution would be to give different names to the parameters.
|
||||||
|
\c;
|
||||||
|
\s;void Test( )
|
||||||
|
\s;{
|
||||||
|
\s; MyClass item1(); // constr. w/o parameters
|
||||||
|
\s; MyClass item2(4, 5); // constr. with 2 parameters
|
||||||
|
\s; MyClass item3; // no constructor called,
|
||||||
|
\s; // therefore item3 == null
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
You can also define a destructor. This must be a \c;void\n; fonction without parameters that has the same name as the class name but prefixed by the ~ character. The destructor is called automatically as soon as the class instance is no more referenced by anyone.
|
||||||
|
\c;
|
||||||
|
\s;public class MyClass
|
||||||
|
\s;{
|
||||||
|
\s; static private int counter = 0; // instance counter
|
||||||
|
\s; void MyClass( )
|
||||||
|
\s; {
|
||||||
|
\s; counter ++; // one instance more
|
||||||
|
\s; }
|
||||||
|
\s; void ~MyClass( )
|
||||||
|
\s; {
|
||||||
|
\s; counter --; // one instance less
|
||||||
|
\s; }
|
||||||
|
\s;}
|
||||||
|
\s;void Test()
|
||||||
|
\s;{
|
||||||
|
\s; MyClass item1( ); // counter = 1
|
||||||
|
\s; MyClass item2( ); // counter = 2
|
||||||
|
\s; item1 = null; // counter = 1
|
||||||
|
\s;} // counter = 0
|
||||||
|
\n;
|
||||||
|
If you pass a class instance as parameter to a \l;function\u cbot\function;, the function only receives a \l;reference\u cbot\pointer; to the instance. That means if you modify the instance in the function, the instance that has been passed to the function will be actuallay modified.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\c;\l;public\u cbot\public;\n;, \c;\l;private\u cbot\private;\n;, \c;\l;static\u cbot\static;\n;, \c;\l;synchronized\u cbot\synchro;\n;, \c;\l;new\u cbot\new;\n;, \c;\l;reference\u cbot\pointer;\n;, \c;\l;this\u cbot\this;\n;
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,8 @@
|
||||||
|
\b;Instruction \c;close\n;
|
||||||
|
Close a file opened previously with \c;\l;open\u cbot\open;\n;. This is a method of the \c;\l;file\u cbot\file;\n; class; therefore you cannot write \c;close()\n; but only \c;handle.close()\n;¦:
|
||||||
|
\c;
|
||||||
|
\s; handle.close();
|
||||||
|
\n;
|
||||||
|
\t;See also
|
||||||
|
\c;\l;file\u cbot\file;\n;, \c;\l;open\u cbot\open;\n;, \c;\l;readln\u cbot\readln;\n;, \c;\l;writeln\u cbot\writeln;\n; and \c;\l;eof\u cbot\eof;\n;.
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,29 @@
|
||||||
|
\b;Conditions
|
||||||
|
A condition is a special \l;expression\u cbot\expr; that returns a \l;boolean\u cbot\bool; value, that can only be either \c;\l;true\u cbot\true;\n; or \c;\l;false\u cbot\false;\n;. With a condition, you can choose f. ex. if the instructions in a \c;\l;while\u cbot\while;\n; loop must be repeated again, or if the instruction in a \c;\l;if\u cbot\if;\n; bloc must be executed.
|
||||||
|
Here are some operators that you can use in conditions to compare two values :
|
||||||
|
|
||||||
|
\c;a == b \n;\c;a\n; equals \c;b\n;
|
||||||
|
\c;a != b \n;\c;a\n; is different from \c;b\n;
|
||||||
|
\c;a < b \n;\c;a\n; smaller than \c;b\n;
|
||||||
|
\c;a <= b \n;\c;a\n; smaller than or equal to \c;b\n;
|
||||||
|
\c;a > b \n;\c;a\n; greater than \c;b\n;
|
||||||
|
\c;a >= b \n;\c;a\n; greater than or equal to \c;b\n;
|
||||||
|
|
||||||
|
For example :
|
||||||
|
|
||||||
|
\c;12 == 12 \n;returns true
|
||||||
|
\c;45 != 47 \n;returns true
|
||||||
|
\c;99 == 98 \n;returns false
|
||||||
|
\c;12 < -1 \n;returns false
|
||||||
|
\c;12 >= 10 \n;returns true
|
||||||
|
\c;12 >= 12 \n;returns true
|
||||||
|
|
||||||
|
\t;Remarque
|
||||||
|
Be careful not to confuse the equality comparison \c;==\n; with the assignment of a \l;variable\u cbot\var; \c;=\n;.
|
||||||
|
|
||||||
|
\c;a == b\n; is an expression that compares \c;a\n; with \c;b\n;.
|
||||||
|
\c;a = b\n; is an expression that copies the value of \c;b\n; into \c;a\n;.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
\b;Instruction \c;continue\n;
|
||||||
|
Syntax :
|
||||||
|
\s;\c;while ( condition )
|
||||||
|
\s;{
|
||||||
|
\s; continue;
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
With this instruction, you can jump over the rest of instructions in the \c;\l;bloc\u cbot\bloc;\n; of a \c;\l;while\u cbot\while;\n; or \c;\l;for\u cbot\for;\n; loop: The execution will resume at the beginning of the bloc, the next time the loop is repeated.
|
||||||
|
|
||||||
|
Here is an example:
|
||||||
|
\s;\c;int i = 0;
|
||||||
|
\s;while ( i < 5 )
|
||||||
|
\s;{
|
||||||
|
\s; i = i+1;
|
||||||
|
\s; if ( i == 3 )
|
||||||
|
\s; {
|
||||||
|
\s; continue;
|
||||||
|
\s; }
|
||||||
|
\s; \n;Instructions ...\c;
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
The instructions will only be executed for the values of \c;i\n; 1, 2, 4 and 5.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,10 @@
|
||||||
|
\b;Instruction \c;deletefile\n;
|
||||||
|
The deletefile instruction deletes an existing file in the files/ folder.
|
||||||
|
|
||||||
|
Files can only be deleted in the files/ folder which is located in the folder where Colobot has been installed. You cannot not delete files that are located elsewhere than in the files/ folder.
|
||||||
|
|
||||||
|
Syntax¦:
|
||||||
|
\s;\c;deletefile ( filename );\n;
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,15 @@
|
||||||
|
\b;Instruction \c;deleteinfo\n;
|
||||||
|
Syntax¦:
|
||||||
|
\s;\c;deleteinfo ( name, power );\n;
|
||||||
|
|
||||||
|
Delete an existing information in the closest \l;information exchange post\u object\exchange;.
|
||||||
|
|
||||||
|
\t;name: \c;string\n;
|
||||||
|
Name of the information to be deleted. This name is a string: it must be written in quotation marks "¦".
|
||||||
|
|
||||||
|
\t;power: \c;float\n;
|
||||||
|
Power of the transmitter, which corresponds to the maximal distance between the sender and the exchange post. If the distance is longer, the information won't be deleted. Default value is 10 metres.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\c;\l;receive\u cbot\receive;\n;, \c;\l;send\u cbot\send;\n; and \c;\l;testinfo\u cbot\testinfo;\n;.
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,15 @@
|
||||||
|
\b;Instruction \c;direction\n;
|
||||||
|
Syntax :
|
||||||
|
\s;\c;direction ( pos );\n;
|
||||||
|
|
||||||
|
Calculates the rotation that a robot must perform in order to point towards a given position.
|
||||||
|
|
||||||
|
\t;pos: \c;\l;point\u cbot\point;\n;
|
||||||
|
Position towards which the robot must point.
|
||||||
|
|
||||||
|
\t;Return value: \c;\l;float\u cbot\float;\n;
|
||||||
|
Angle of the rotation that must be performed. -90 means f. ex. a rotation of 90 degrees to the right.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
\b;Instruction \c;distance\n;
|
||||||
|
With the instruction \c;distance( , )\n; you can calculate the distance between two positions.
|
||||||
|
|
||||||
|
\b;Basic use
|
||||||
|
If you write \c;position\n; alone, this gives you the position of the bot that executes the program. If you write the name of a variable followed by \c;.position\n;, this gives you the position of the object described in the variable.
|
||||||
|
|
||||||
|
Here is a program that moves forward, covering exactly the distance between the bot and the closest ant:
|
||||||
|
\c;
|
||||||
|
\s; item = \l;radar\u cbot\radar;(AlienAnt);
|
||||||
|
\s; \l;move\u cbot\move;(distance(position, item.position));
|
||||||
|
\n;
|
||||||
|
This is of course pure suicide. Better to stop 40 meters before, in order to be at shooting range:
|
||||||
|
\c;
|
||||||
|
\s; item = radar(AlienAnt);
|
||||||
|
\s; move(distance(position, item.position) - 40);
|
||||||
|
\n;
|
||||||
|
\b;For specialists
|
||||||
|
Syntax:
|
||||||
|
\s;\c;distance ( pos1, pos2 );\n;
|
||||||
|
|
||||||
|
Calculates the distance between two positions.
|
||||||
|
|
||||||
|
\t;pos1, pos2: \c;\l;point\u cbot\point;\n;
|
||||||
|
Coordinates of the two positions.
|
||||||
|
|
||||||
|
\t;Return value: \c;\l;float\u cbot\float;\n;
|
||||||
|
Distance between the two positions.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,14 @@
|
||||||
|
\b;Instruction \c;distance2d\n;
|
||||||
|
Syntax:
|
||||||
|
\s;\c;distance2d ( pos1, pos2 );\n;
|
||||||
|
|
||||||
|
Calculates the distance between two positions (ignores the z coordinate).
|
||||||
|
|
||||||
|
\t;pos1, pos2: \c;\l;point\u cbot\point;\n;
|
||||||
|
Coordinates of the two positions.
|
||||||
|
|
||||||
|
\t;Return value: \c;\l;float\u cbot\float;\n;
|
||||||
|
Distance between the two positions.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,28 @@
|
||||||
|
\b;Instruction \c;do - while\n;
|
||||||
|
Syntax:
|
||||||
|
\s;\c;do
|
||||||
|
\s;{
|
||||||
|
\s; \n;Instructions ...\c;
|
||||||
|
\s;}
|
||||||
|
\s;while ( condition );
|
||||||
|
\n;
|
||||||
|
This instruction allows you to perform several times the instructions inside the \l;block\u cbot\bloc;. The instructions are executed at least once, because the condition is tested only afterwards.
|
||||||
|
Be careful not to confuse the instruction \c;do { } while ( );\n; with the instruction \c;\l;while\u cbot\while; ( ) { }\n;; the latter tests the condition before the instructions in the block are executed.
|
||||||
|
|
||||||
|
\t;\c;condition\n;
|
||||||
|
The instructions in the block are performed over and over again, as long as the \l;condition\u cbot\cond; is true.
|
||||||
|
|
||||||
|
Here is an example :
|
||||||
|
\s;\c;do
|
||||||
|
\s;{
|
||||||
|
\s; p = radar(TitaniumOre);
|
||||||
|
\s;}
|
||||||
|
\s;while ( p == null );
|
||||||
|
\n;
|
||||||
|
\t;Attention
|
||||||
|
Always put a \l;semicolon\u cbot\term; at the end of the line \c;while ( )\n;.
|
||||||
|
|
||||||
|
The instructions \c;\l;break\u cbot\break;\n; and \c;\l;continue\u cbot\continue;\n; can be useful inside a block following the instruction \c;do { }\n;.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Instructions\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,29 @@
|
||||||
|
\b;Instruction \c;drop\n;
|
||||||
|
The instruction \c;drop();\n; instructs the bot to drop whatever the operating arm is carrying on the ground, on the platform of a building or on the power cell location of a bot.
|
||||||
|
|
||||||
|
\b;Basic use
|
||||||
|
The instruction \c;drop();\n; written in this form drops the object in front of the bot. Here is a short program that grabs an object in front of the bot and drops it 5 meters further:
|
||||||
|
\c;
|
||||||
|
\s; \l;grab\u cbot\grab;();
|
||||||
|
\s; \l;move\u cbot\move;(5);
|
||||||
|
\s; drop();
|
||||||
|
\n;
|
||||||
|
\b;For specialists
|
||||||
|
Syntax:
|
||||||
|
\s;\c;drop ( oper );\n;
|
||||||
|
|
||||||
|
This instruction appeals to the operating arm of a \l;grabber bot\u object\botgr;, in order to drop what it is holding.
|
||||||
|
|
||||||
|
\t;oper: \c;\l;int\u cbot\int;\n; (default value\c;InFront\n;)
|
||||||
|
Oper indicates where the robot should drop the object. If no indication is given, the object is dropped in front of the bot.
|
||||||
|
\c;InFront \n; Drops in front (default value).
|
||||||
|
\c;Behind \n; Drops behind.
|
||||||
|
\c;EnergyCell\n; Drops on the bot's own power cell location.
|
||||||
|
|
||||||
|
\t;Return value: \c;\l;int\u cbot\int;\n;
|
||||||
|
Normally an error stops the program. You can prevent the program from stopping on errors by using the \c;\l;errmode\u cbot\errmode;(0)\n; instruction. A value different from zero if an error occurred is then returned by \c;drop();\n;.
|
||||||
|
\c;== 0 \n;object was dropped
|
||||||
|
\c;!= 0 \n;error, no object was dropped
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,15 @@
|
||||||
|
\b;Instruction \c;eof\n;
|
||||||
|
Test the end of file condition of an open file. This is a method of the \c;\l;file\u cbot\file;\n; class; therefore you cannot write \c;eof()\n; but only \c;handle.eof()\n;¦:
|
||||||
|
\c;
|
||||||
|
\s; if ( handle.eof() )
|
||||||
|
\n;
|
||||||
|
Example¦:
|
||||||
|
\c;
|
||||||
|
\s; while ( not handle.eof() )
|
||||||
|
\s; {
|
||||||
|
\s; s = handle.readln();
|
||||||
|
\s; }
|
||||||
|
\n;
|
||||||
|
\t;See also
|
||||||
|
\c;\l;file\u cbot\file;\n;, \c;\l;open\u cbot\open;\n;, \c;\l;close\u cbot\close;\n;, \c;\l;readln\u cbot\readln;\n; and \c;\l;writeln\u cbot\writeln;\n;.
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,33 @@
|
||||||
|
\b;Instruction \c;errmode\n;
|
||||||
|
The \c;errmode();\n; instruction allows you to chose if the program should stop when an error occurs in one of the following instructions: \c;\l;goto\u cbot\goto;\n;, \c;\l;move\u cbot\move;\n;, \c;\l;grab\u cbot\grab;\n;, \c;\l;drop\u cbot\drop;\n;, etc.
|
||||||
|
|
||||||
|
\b;For specialists
|
||||||
|
Syntax¦:
|
||||||
|
\s;\c;errmode ( mode );\n;
|
||||||
|
|
||||||
|
Normally the program is stopped when an error occurs. If you use the instruction \c;errmode(0);\n; at the beginning of the program, the instructions listed above return a value different from zero if the instruction could not be performed.
|
||||||
|
|
||||||
|
\t;mode: \c;\l;float\u cbot\float;\n; (\c;1\n; per default)
|
||||||
|
Error treatment mode.
|
||||||
|
\c;0\n; -> continues program execution and returns a non zero value
|
||||||
|
\c;1\n; -> stops the program (default behavior)
|
||||||
|
|
||||||
|
Exemple 1¦:
|
||||||
|
\s;\c;errmode(0);
|
||||||
|
\s;while ( goto(pos) != 0 )
|
||||||
|
\s;{
|
||||||
|
\s; wait(2);
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
Exemple 2¦:
|
||||||
|
\s;\c;errmode(0);
|
||||||
|
\s;int err;
|
||||||
|
\s;err = goto(pos);
|
||||||
|
\s;if ( err != 0 )
|
||||||
|
\s;{
|
||||||
|
\s; \n;goto did not perform correctly ...\c;
|
||||||
|
\s; \n;take some appropriate action ...\c;
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,88 @@
|
||||||
|
\b;Expressions
|
||||||
|
Expressions can include the following operators:
|
||||||
|
|
||||||
|
\c;+\n; addition
|
||||||
|
\c;-\n; subtraction
|
||||||
|
\c;*\n; multiplication
|
||||||
|
\c;/\n; division
|
||||||
|
\c;%\n; remainder of the division (only for the type \c;\l;int\u cbot\int;\n;)
|
||||||
|
|
||||||
|
With the addition operator \c;+\n;, you can not only add numbers, you can also append \l;strings\u cbot\string;.
|
||||||
|
\c;
|
||||||
|
\s; int i = 12+3; // returns 15
|
||||||
|
\s; string s = "a"+"bc"; // returns "abc"
|
||||||
|
\s; int i = 2-5; // returns -3
|
||||||
|
\s; float f = 3.01*10; // returns 30.1
|
||||||
|
\s; int i = 5/3; // returns 1
|
||||||
|
\s; float f = 5/3; // returns 1.67
|
||||||
|
\s; float f = 5/0; // returns an error
|
||||||
|
\s; int i = 13%5; // returns 3
|
||||||
|
\s; int i = -8%3; // returns -2
|
||||||
|
\n;
|
||||||
|
An expression can include constants or \l;variables\u cbot\var;. For example:
|
||||||
|
|
||||||
|
\s;\c; 12+dist\n;
|
||||||
|
|
||||||
|
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:
|
||||||
|
\c;
|
||||||
|
\s; 12*a+b/c \n;is equivalent to\c; (12*a)+(b/c)
|
||||||
|
\s; 2.5*(dist+range)
|
||||||
|
\n;
|
||||||
|
In order to improve readability, you can put as many spaces as you want:
|
||||||
|
\c;
|
||||||
|
\s; 12*a + b/c
|
||||||
|
\s; 2.5 * (dist+range)
|
||||||
|
\n;
|
||||||
|
Here is a list of mathematical functions:
|
||||||
|
|
||||||
|
\c;sin(angle) \n;sinus
|
||||||
|
\c;cos(angle) \n;cosinus
|
||||||
|
\c;tan(angle) \n;tangent
|
||||||
|
\c;asin(value) \n;arc-sinus
|
||||||
|
\c;acos(value) \n;arc-cosinus
|
||||||
|
\c;atan(value) \n;arc-tangente
|
||||||
|
\c;sqrt(value) \n;square root
|
||||||
|
\c;pow(x, y) \n;x power y
|
||||||
|
\c;rand() \n;random value ranging between 0 and 1
|
||||||
|
|
||||||
|
Angles are in degrees.
|
||||||
|
|
||||||
|
\t;Compound assignment operators (for specialists)
|
||||||
|
Besides the \c;=\n; operators for variable assignment there are several compound-assignment operators.
|
||||||
|
|
||||||
|
The compound-assignment operators combine the \c;=\n; assignment operator with another binary operator such as \c;+\n; or \c;-\n;. Compound-assignment operators perform the operation specified by the additional operator and then assign the result to the left operand. For example, a compound-assignment expression such as
|
||||||
|
|
||||||
|
\c;\s;expression1 += expression2
|
||||||
|
|
||||||
|
is equivalent to
|
||||||
|
|
||||||
|
\c;\s;expression1 = expression1 + expression2
|
||||||
|
|
||||||
|
\c;+=\n; addition
|
||||||
|
\c;-=\n; subtraction
|
||||||
|
\c;*=\n; multiplication
|
||||||
|
\c;/=\n; division
|
||||||
|
\c;%=\n; remainder of the division (only for the type \c;\l;int\u cbot\int;\n;)
|
||||||
|
|
||||||
|
\t;Prefix and posfix increment- and decrement operators (for specialists)
|
||||||
|
The operators \c;++\n; and \c;--\n; allow you to increment (++) or to decrement (--) a variable in very compact and efficient manner.
|
||||||
|
|
||||||
|
For example to increment the variable \c;a\n; you can write
|
||||||
|
\c;\s; a++ ;
|
||||||
|
\n;instead of
|
||||||
|
\c;\s; a = a + 1 ;
|
||||||
|
\n;
|
||||||
|
The value of the expression \c;a++\n; is the value of the variable \c;a\n; before the increment. If you use the prefix operator \c;++a\n; the value of the expression is the value of the variable \c;a\n; after the increment. The same holds for the \c;--\n; decrement operator.
|
||||||
|
|
||||||
|
Exemples:
|
||||||
|
\c;\s; a = 2 ;
|
||||||
|
\s; b = a++ ;
|
||||||
|
\s; // now b contains 2 and a contains 3
|
||||||
|
|
||||||
|
\c;\s; a = 2 ;
|
||||||
|
\s; b = ++a ;
|
||||||
|
\s; // now b contains 3 and a contains 3
|
||||||
|
\n;
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,30 @@
|
||||||
|
\b;Instruction \c;extern\n;
|
||||||
|
The \c;extern\n; instruction determines the \l;function\u cbot\function; that acts as main program of a robot. The name of the function declared with \c;extern\n; will apear in the program list in the lower left corner of the screen.
|
||||||
|
\c;
|
||||||
|
\s;extern void object::MowDown( )
|
||||||
|
\s;{
|
||||||
|
\s; while ( true )
|
||||||
|
\s; {
|
||||||
|
\s; fire(1);
|
||||||
|
\s; turn(10);
|
||||||
|
\s; }
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
If the program contains other functions, only the main function must be preceded by \c;extern\n;.
|
||||||
|
\c;
|
||||||
|
\s;extern void object::Square( )
|
||||||
|
\s;{
|
||||||
|
\s; for ( int i=0 ; i<4 ; i++ )
|
||||||
|
\s; {
|
||||||
|
\s; Line(10);
|
||||||
|
\s; }
|
||||||
|
\s;}
|
||||||
|
\s;
|
||||||
|
\s;void object::Line(float dist)
|
||||||
|
\s;{
|
||||||
|
\s; move(dist);
|
||||||
|
\s; turn(90);
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,6 @@
|
||||||
|
\b;Type \c;false\n;
|
||||||
|
This value means that a condition is not true; it is one of the two values that a \l;boolean\u cbot\bool; \l;variable\u cbot\var; can take.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
\b;Type \c;file\n;
|
||||||
|
This type is used for accessing files in the files/ folder.
|
||||||
|
\c;
|
||||||
|
\s; file handle();
|
||||||
|
\n;
|
||||||
|
Use the syntax above for declaring a file handle. You must use () to create an instance of the \c;file\n; class. Without the () the handle would have the value \c;\l;null\u cbot\null;\n;.
|
||||||
|
|
||||||
|
Files can only be created and opened in the files/ folder which is located in the folder where Colobot has been installed. You cannot not create or open files elsewhere than in the files/ folder.
|
||||||
|
|
||||||
|
\b;For specialists
|
||||||
|
\c;file\n; is actually not a simple type but a class. \c;open\n;, \c;close\n;, \c;writeln\n; etc. are methods of the \c;file\n; class. This is the reason why we always write \c;handle.method()\n;¦:
|
||||||
|
\c;
|
||||||
|
\s; handle.open("test.txt", "w");
|
||||||
|
\s; handle.close();
|
||||||
|
\n;
|
||||||
|
\t;See also
|
||||||
|
\c;\l;open\u cbot\open;\n;, \c;\l;close\u cbot\close;\n;, \c;\l;readln\u cbot\readln;\n;, \c;\l;writeln\u cbot\writeln;\n; and \c;\l;eof\u cbot\eof;\n;.
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,31 @@
|
||||||
|
\b;Instruction \c;fire\n;
|
||||||
|
The instruction \c;fire();\n; fires the bot's onboard cannon.
|
||||||
|
|
||||||
|
\b;Basic use
|
||||||
|
Generally this instruction is used to shoot one-second bursts:
|
||||||
|
\c;
|
||||||
|
\s; fire(1);
|
||||||
|
\n;
|
||||||
|
\b;For specialists
|
||||||
|
Syntax:
|
||||||
|
\s;\c;fire ( time );\n;
|
||||||
|
|
||||||
|
Fires the gun, with a burst that lasts a certain time. The longer the burst, the more energy it needs. This instruction can be used with the following bot types:
|
||||||
|
o \l;Shooter\u object\botfr;
|
||||||
|
o \l;Orga shooter\u object\botor;
|
||||||
|
o \l;Phazer shooter\u object\botphaz;
|
||||||
|
|
||||||
|
When controlling the robot through programming, the only way to turn the gun left or right is to turn the whole robot with the instruction \c;\l;turn\u cbot\turn;\n;.
|
||||||
|
|
||||||
|
In order to move the gun upward or downward, use the instruction \c;\l;aim\u cbot\aim;\n;.
|
||||||
|
|
||||||
|
\t;time: \c;\l;float\u cbot\float;\n;
|
||||||
|
Duration of the burst. Generally, the value given is 1. Shorter bursts can also be performed in order to spare time and energy.
|
||||||
|
|
||||||
|
\t;Return value: \c;\l;int\u cbot\int;\n;
|
||||||
|
Zero if OK, or a value different from zero if an error occurred.
|
||||||
|
\c;== 0 \n;the cannon has been fired
|
||||||
|
\c;!= 0 \n;error, the cannon could not be fired
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,17 @@
|
||||||
|
\b;Instruction \c;flatground\n;
|
||||||
|
Syntax¦:
|
||||||
|
\s;\c;flatground ( center, rmax );\n;
|
||||||
|
|
||||||
|
Calculates the maximal radius of a flat zone on which a building ca be built.
|
||||||
|
|
||||||
|
\t;center: \c;\l;point\u cbot\point;\n;
|
||||||
|
Center of the circlular zone.
|
||||||
|
|
||||||
|
\t;rmax: \c;\l;float\u cbot\float;\n;
|
||||||
|
Maximal radius.
|
||||||
|
|
||||||
|
\t;Return value: \c;\l;float\u cbot\float;\n;
|
||||||
|
Radius of the flat zone (always between 0 and rmax).
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,25 @@
|
||||||
|
\b;Type \c;float\n;
|
||||||
|
Use this type for most variables that contains numbers. Variables of this type can contain positive and negative numbers, whole or real numbers, for example:
|
||||||
|
\c;
|
||||||
|
\s; 12.9
|
||||||
|
\s; 1.125
|
||||||
|
\s; 0.002
|
||||||
|
\s; -4.1
|
||||||
|
\n;
|
||||||
|
If you need only whole numbers (f. ex. 12 or -5000), you should rather use the type \c;\l;int\u cbot\int;\n;.
|
||||||
|
|
||||||
|
\t;Attention
|
||||||
|
Do not insert space or colon characters into a number. To separate the whole part from the fractional part, use a dot.
|
||||||
|
\c;
|
||||||
|
\s; Write and not
|
||||||
|
\s; 12.56 12 . 56
|
||||||
|
\s; -54.34 -54,34
|
||||||
|
\s;12895.69 12,895.69
|
||||||
|
\n;
|
||||||
|
\t;For specialists
|
||||||
|
Floating point numbers are represented in Colobot with 32 bits.
|
||||||
|
The highest value that can be represented is 3.4E+38.
|
||||||
|
The smallest value that can be represented is 3.4E-38.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,40 @@
|
||||||
|
\b;Instruction \c;for\n;
|
||||||
|
Syntax:
|
||||||
|
\s;\c;for ( before ; condition ; end )
|
||||||
|
\s;{
|
||||||
|
\s; \n;Instructions ...\c;
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
This instruction allows you to execute a certain number of times the instructions contained in the \l;block\u cbot\bloc;.
|
||||||
|
|
||||||
|
\t;\c;before\n;
|
||||||
|
This instruction is executed before the first loop instance.
|
||||||
|
|
||||||
|
\t;\c;condition\n;
|
||||||
|
This \l;condition\u cbot\cond; determines if another instance of the loop must be executed. It is tested before every instance of the loop.
|
||||||
|
|
||||||
|
\t;\c;end\n;
|
||||||
|
This instruction is executed at the end of every instance of the loop.
|
||||||
|
|
||||||
|
Example: count from 1 to 4
|
||||||
|
\c;\s;\c;for ( i = 0 ; i <= 4 ; i++ )
|
||||||
|
\s;{
|
||||||
|
\s; message(i) ;
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
The following example is strictly equivalent to a \c;for\n;-loop, but it uses the instruction \c;\l;while\u cbot\while;\n;:
|
||||||
|
\s;\c;before;
|
||||||
|
\s;while ( condition )
|
||||||
|
\s;{
|
||||||
|
\s; \n;Instructions ...\c;
|
||||||
|
\s; end;
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
\t;Attention
|
||||||
|
Do not put a \l;semicolon\u cbot\term; at the end of the line \c;for ( )\n;.
|
||||||
|
|
||||||
|
The instructions \c;\l;break\u cbot\break;\n; and \c;\l;continue\u cbot\continue;\n; can be useful inside a block following the instruction \c;for \n;.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
||||||
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
\b;Functions
|
||||||
|
With functions you can divide your program into several parts, each of them will execute a specific task.
|
||||||
|
Let's imagine following program¦:
|
||||||
|
\c;
|
||||||
|
\s;extern void object::Remote( )
|
||||||
|
\s;{
|
||||||
|
\s; send("order", 1, 100);
|
||||||
|
\s; wait(5);
|
||||||
|
\s; send("order", 3, 100);
|
||||||
|
\s; wait(5);
|
||||||
|
\s; send("order", 2, 100);
|
||||||
|
\s; wait(5);
|
||||||
|
\s; send("order", 4, 100);
|
||||||
|
\s; wait(5);
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
\c;send\n; and \c;wait\n; are repeated several times. So it would be a good thing if we created a function that executes these two instructions:
|
||||||
|
\c;
|
||||||
|
\s;void object::SendToPost( float op )
|
||||||
|
\s;{
|
||||||
|
\s; send("order", op, 100);
|
||||||
|
\s; wait(5);
|
||||||
|
\s;}
|
||||||
|
\s;extern void object::Remote( )
|
||||||
|
\s;{
|
||||||
|
\s; SendToPost(1);
|
||||||
|
\s; SendToPost(3);
|
||||||
|
\s; SendToPost(2);
|
||||||
|
\s; SendToPost(4);
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
A function can have paramteters¦:
|
||||||
|
\c;
|
||||||
|
\s;void Example( int a, float x, string s )
|
||||||
|
\n;
|
||||||
|
The \c;Exemple\n; function will reveive un integer \c;a\n;, a floating point number \c;x\n; and a string \c;s\n;. Parameters are "passed by value", that is the values of parameter variables in a function are copies of the values the caller specified as variables. If you pass an \c;int\n; to a function, its parameter is a copy of whatever value was being passed as argument, and the function can change its parameter value without affecting values in the code that invoked the function.
|
||||||
|
|
||||||
|
If you pass a \l;class\u cbot\class; instance or an \l;array\u cbot\array; as parameter to a function, the function only receives a \l;reference\u cbot\pointer; to the instance or the array. That means if you modify the instance or the array in the function, the instance or the array that has been specified by the caller will be actuallay modified.
|
||||||
|
|
||||||
|
A function can also return a result with the \c;\l;return\u cbot\return;\n; instruction. Therefore the function must be declared no longer as void but as a type:
|
||||||
|
\c;
|
||||||
|
\s;float Mean( float a, float b )
|
||||||
|
\s;{
|
||||||
|
\s; return (a+b)/2;
|
||||||
|
\s;}
|
||||||
|
\s;
|
||||||
|
\s;extern void object::Test( )
|
||||||
|
\s;{
|
||||||
|
\s; float value;
|
||||||
|
\s; value = Mean(2, 6);
|
||||||
|
\s; message( value ); // will display 4
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
Some other examples¦:
|
||||||
|
\c;
|
||||||
|
\s;float Pi( )
|
||||||
|
\s;{
|
||||||
|
\s; return 3.1415;
|
||||||
|
\s;}
|
||||||
|
\s;
|
||||||
|
\s;string Sign( float a )
|
||||||
|
\s;{
|
||||||
|
\s; if ( a > 0 ) return "positive";
|
||||||
|
\s; if ( a < 0 ) return "négative";
|
||||||
|
\s; return "null";
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
You can declare several functions with the same name but different parameters¦:
|
||||||
|
\c;
|
||||||
|
\s;float Pythagoras( float a, float b )
|
||||||
|
\s;{
|
||||||
|
\s; return sqrt((a*a)+(b*b));
|
||||||
|
\s;}
|
||||||
|
\s;
|
||||||
|
\s;float Pythagoras( float a, float b, float c )
|
||||||
|
\s;{
|
||||||
|
\s; return sqrt((a*a)+(b*b)+(c*c));
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
CBOT will call either the one or the other function depending on the paramteres passed.
|
||||||
|
|
||||||
|
You can also declare a function \l;public\u cbot\public; so it can be used by other bots.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,35 @@
|
||||||
|
\b;Instruction \c;goto\n;
|
||||||
|
The instruction \c;goto();\n; instructs the bot to reach a given position.
|
||||||
|
|
||||||
|
\b;Basic use
|
||||||
|
The most current use consists in moving the bot to an object located with the instruction \c;\l;radar\u cbot\radar;();\n;. If the information returned by the \c;\l;radar\u cbot\radar;();\n; has been stored in a certain variable, write the name of the variable followed by \c;.position\n; in order to get the position of the object. Here is an example of a program that looks for a \l;titanium cube\u object\titan;, goes to the position and grabs it:
|
||||||
|
\c;
|
||||||
|
\s; item = \l;radar\u cbot\radar;(Titanium);
|
||||||
|
\s; goto(item.position);
|
||||||
|
\s; \l;grab\u cbot\grab;();
|
||||||
|
\n;
|
||||||
|
\b;For specialists
|
||||||
|
Syntax:
|
||||||
|
\s;\c;goto ( position, altitude, goal, crash );\n;
|
||||||
|
|
||||||
|
Tells the robot to go to the given position, avoiding all the obstacles if this is possible.
|
||||||
|
|
||||||
|
\t;pos: \c;\l;point\u cbot\point;\n;
|
||||||
|
Coordinates of the goal position.
|
||||||
|
|
||||||
|
\t;altitude: \c;\l;float\u cbot\float;\n;
|
||||||
|
Flight altitude for \l;winged bots\u object\botgj;. The altitude is useful only for \l;winged bots\u object\botgj;. From the initial altitude, the bot climbs higher until it reaches the specified hight. When arriving close to destination, it goes down to touch the ground at the given position. If no value is given, an altitude of 10 meters is the default value. On very short moves, even winged bot stay on the ground. For all bot except winged bots, this parameter is ignored.
|
||||||
|
|
||||||
|
\t;goal: \c;\l;int\u cbot\int;\n; (default value \c;0\n;)
|
||||||
|
This parameter tells the bot how it must reach the goal:
|
||||||
|
\c;0\n; stops exactly at the goal position
|
||||||
|
\c;1\n; goes close to the goal position, without stopping.
|
||||||
|
If no value is given, \c;1\n; (precision) is the default value.
|
||||||
|
|
||||||
|
\t;Return value: \c;\l;int\u cbot\int;\n;
|
||||||
|
Normally an error stops the program. You can prevent the program from stopping on errors by using the \c;\l;errmode\u cbot\errmode;(0)\n; instruction. A value different from zero if an error occurred is then returned by \c;goto()\n;.
|
||||||
|
\c;== 0 \n;Goal position reached
|
||||||
|
\c;!= 0 \n;Goal position impossible to reach
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,29 @@
|
||||||
|
\b;Instruction \c;grab\n;
|
||||||
|
The instruction \c;grab();\n; instructs the bot to use the operating arm to grab an object located on the ground, on the platform of a building or on the power cell location of a bot.
|
||||||
|
|
||||||
|
\b;Basic use
|
||||||
|
The instruction \c;grab();\n; written in this form grabs the object located in front of the bot. Here is a short program that grabs an object in front of the bot and drops it 5 meters further:
|
||||||
|
\c;
|
||||||
|
\s; grab();
|
||||||
|
\s; \l;move\u cbot\move;(5);
|
||||||
|
\s; \l;drop\u cbot\drop;();
|
||||||
|
\n;
|
||||||
|
\b;For specialists
|
||||||
|
Syntax:
|
||||||
|
\s;\c;grab ( oper );\n;
|
||||||
|
|
||||||
|
This instruction appeals to the operating arm of a \l;grabber bot\u object\botgr;, in order to grab the closest object.
|
||||||
|
|
||||||
|
\t;oper: \c;\l;int\u cbot\int;\n; (default value\c;InFront\n;)
|
||||||
|
Oper indicates where the bot should look for an object to grab. If no indication is given, the object is picked up in front of the bot.
|
||||||
|
\c;InFront \n; Grabs in front (default value).
|
||||||
|
\c;Behind \n; Grabs behind.
|
||||||
|
\c;EnergyCell\n; Grabs the bot's own power cell.
|
||||||
|
|
||||||
|
\t;Return value: \c;\l;int\u cbot\int;\n;
|
||||||
|
Normally an error stops the program. You can prevent the program from stopping on errors by using the \c;\l;errmode\u cbot\errmode;(0)\n; instruction. A value different from zero if an error occurred is then returned by \c;grab();\n;.
|
||||||
|
\c;== 0 \n;an object was grabbed
|
||||||
|
\c;!= 0 \n;error, no object was grabbed
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,40 @@
|
||||||
|
\b;Instructions \c;if\n; and \c;else\n;
|
||||||
|
With the instruction \c;if() {}\n; you can execute a set of instructions only if a certain condition is true. Write the condition in brackets \c;()\n;, and the instructions in braces \c;{}\n;.
|
||||||
|
|
||||||
|
\b;Basic use
|
||||||
|
Here is a concrete example: The bot will shoot only if the target is closer than 40 meters:
|
||||||
|
\c;
|
||||||
|
\s; item = \l;radar\u cbot\radar;(AlienAnt);
|
||||||
|
\s; if (\l;distance\u cbot\dist;(position, item.position) < 40)
|
||||||
|
\s; {
|
||||||
|
\s; fire(1);
|
||||||
|
\s; }
|
||||||
|
\n;
|
||||||
|
You can also test if an object exists at all. If the instruction \c;\l;radar\u cbot\radar;();\n; does not find the requested object, it returns the value \c;null\n;. So you can test if an object does not exists with the condition \c;(item == null)\n;, or test if it exists with \c;(item != null)\n;. Two equal signs \c;==\n; test equality, an exclamation mark followed by an equal sign \c;!=\n; test inequality. Here is a test that will go to rechage the \l;power cell\u object\power; only if there is a \l;power station\u object\station;:
|
||||||
|
\c;
|
||||||
|
\s; item = \l;radar\u cbot\radar;(PowerStation);
|
||||||
|
\s; if (item != null)
|
||||||
|
\s; {
|
||||||
|
\s; \l;goto\u cbot\goto;(item.position);
|
||||||
|
\s; \l;wait\u cbot\wait;(5);
|
||||||
|
\s; }
|
||||||
|
\n;
|
||||||
|
\b;For specialists
|
||||||
|
Syntax:
|
||||||
|
\s;\c;if ( condition )
|
||||||
|
\s;{
|
||||||
|
\s; \n;Instructions A ...\c;
|
||||||
|
\s;}
|
||||||
|
\s;else
|
||||||
|
\s;{
|
||||||
|
\s; \n;Instructions B ...\c;
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
With this conditional structure you can execute a \l;bloc\u cbot\bloc; A or a \l;bloc\u cbot\bloc; B depending on a \l;condition\u cbot\cond;. If the condition is true, bloc A is executed. If the condition is false, bloc B is executed.
|
||||||
|
Part \c;else { }\n; is not compulsory.
|
||||||
|
|
||||||
|
\t;Attention
|
||||||
|
Do not put a \l;semicolon\u cbot\term; at the end of the line \c;if ( )\n;.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,20 @@
|
||||||
|
\b;Type \c;int\n;
|
||||||
|
Use this type for variables that contain only whole numbers, negative or positive. For example:
|
||||||
|
\c;
|
||||||
|
\s; 12
|
||||||
|
\s; 1000
|
||||||
|
\s; -4
|
||||||
|
\n;
|
||||||
|
To represent real numbers like 12.05 or -0.005, use the type \c;\l;float\u cbot\float;\n;.
|
||||||
|
|
||||||
|
\t;Attention
|
||||||
|
Do not put space or colon signs inside a number.
|
||||||
|
|
||||||
|
\t;For specialists
|
||||||
|
Numbers of the type \c;int\n; are represented with 32 bits.
|
||||||
|
The highest number that can be represented is (2^31)-1, that is 2'147'483'647.
|
||||||
|
The smallest number that can be represented is -(2^31), that is -2'147'483'648.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
\b;Instruction \c;jet\n;
|
||||||
|
Syntax:
|
||||||
|
\s;\c;jet ( power );\n;
|
||||||
|
|
||||||
|
Direct control of the jet of a \l;winged bot\u object\botgj;. The jet is what makes the bot fly. Use this instruction in order to take off, climb, descend or land.
|
||||||
|
|
||||||
|
\t;power: \c;\l;float\u cbot\float;\n;
|
||||||
|
Power of the jet, ranges between \c;-1\n; and \c;+1\n;. \c;jet(1);\n; instructs the bot to climb as fast as possible, \c;jet(-1);\n; descends as fast as possible, \c;jet(0);\n; stabilizes the altitude. In order to get slower altitude changes, use intermediate values, for example \c;jet(0.3);\n;.
|
||||||
|
|
||||||
|
|
||||||
|
\t;Return value: \c;\l;void\u cbot\void;\n;
|
||||||
|
None.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
\b;Instruction \c;message\n;
|
||||||
|
Syntax:
|
||||||
|
\s;\c;message ( text, type );\n;
|
||||||
|
|
||||||
|
Prints a message on top of the screen. After a few seconds, the message disappears automatically.
|
||||||
|
|
||||||
|
\t;text: \c;\l;string\u cbot\string;\n;
|
||||||
|
Text that is to be displayed. It is possible to append several texts and/or values with the operator \c;+\n;:
|
||||||
|
\c;message("Not found");\n;
|
||||||
|
\c;message(angle);\n;
|
||||||
|
\c;message(n + " object(s) found");\n;
|
||||||
|
\c;message("Distance = " + dist + " meters");\n;
|
||||||
|
|
||||||
|
\t;type: \c;\l;int\u cbot\int;\n; (default value \c;DisplayMessage\n;)
|
||||||
|
Type of the message, that determines the background color.
|
||||||
|
o \c;DisplayMessage\n; Standard message on yellow background.
|
||||||
|
o \c;DisplayInfo \n; Information on green background.
|
||||||
|
o \c;DisplayWarning\n; Warning on blue background.
|
||||||
|
o \c;DisplayError \n; Error on red background.
|
||||||
|
|
||||||
|
\t;Return value: \c;\l;void\u cbot\void;\n;
|
||||||
|
None.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,39 @@
|
||||||
|
\b;Instruction \c;motor\n;
|
||||||
|
The instruction \c;motor( , );\n; sets the speed for the left-hand and the right-hand motor of the bot.
|
||||||
|
|
||||||
|
\b;Basic use
|
||||||
|
The speed given to the motors will remain constant during the execution of the following instructions. Thanks to this characteristic it is possible to perform a rotation during the instruction \c;\l;fire\u cbot\fire;();\n;. This will sweep a whole zone with only one burst. Here is an example that will sweep the zone in front of the bot:
|
||||||
|
\c;
|
||||||
|
\s; \l;turn\u cbot\turn;(45); // turns 45 degrees left
|
||||||
|
\s; motor(0.5, -0.5); // slow rotation to the right
|
||||||
|
\s; \l;fire\u cbot\fire;(2); // fire
|
||||||
|
\s; motor(0,0); // stops the rotation
|
||||||
|
\n;
|
||||||
|
With the left-hand motor turning half-speed forward and the right-hand motor turning half-speed backward, the bot will turn slowly on itself during the 2-second-burst.
|
||||||
|
|
||||||
|
\b;For specialists
|
||||||
|
Syntax :
|
||||||
|
\s;\c;motor ( left, right );\n;
|
||||||
|
|
||||||
|
Gives speed instructions to the right and left motors of the robot. The motors will keep this speed until a new motor instruction is performed, or until a \c;\l;move\u cbot\move;\n;, \c;\l;turn\u cbot\turn;\n; or \c;\l;goto\u cbot\goto;\n; instruction is performed.
|
||||||
|
|
||||||
|
\t;left: \c;\l;float\u cbot\float;\n;
|
||||||
|
Speed instruction for the left motor; the value must range between -1 and 1.
|
||||||
|
|
||||||
|
\t;right: \c;\l;float\u cbot\float;\n;
|
||||||
|
Speed instruction for the right motor; the value must range between -1 and 1.
|
||||||
|
|
||||||
|
Examples :
|
||||||
|
\c;motor(1, 1);\n; moves forward with highest possible speed.
|
||||||
|
\c;motor(-0.5, -0.5);\n; moves backward with half speed.
|
||||||
|
\c;motor(1, -1);\n; turns right as fast as possible.
|
||||||
|
|
||||||
|
Note :
|
||||||
|
\c;motor(2, 2);\n; will not move forward any faster than \c;motor(1, 1)\n;
|
||||||
|
\c;motor(-2, -2);\n; will not move backward any faster than \c;motor(-1, -1)\n;
|
||||||
|
|
||||||
|
\t;Return value: \c;\l;void\u cbot\void;\n;
|
||||||
|
None.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Instructions\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,22 @@
|
||||||
|
\b;Instruction \c;move\n;
|
||||||
|
The instruction \c;move();\n; instructs the bot to move forward or backward while keeping the same orientation. In brackets you must specify the length of the move in meters.
|
||||||
|
|
||||||
|
\b;Basic use
|
||||||
|
If you want the bot to move forward 30 meters, write \c;move(30);\n;. In order to move the bot backward after it dropped a chunk of \l;titanium ore\u object\titanore; on the \l;converter\u object\convert;, write \c;move(-2.5);\n;.
|
||||||
|
|
||||||
|
\b;For specialists
|
||||||
|
Syntax:
|
||||||
|
\s;\c;move ( length );\n;
|
||||||
|
|
||||||
|
Moves forward or backward of a given distance, always keeping the current orientation of the bot.
|
||||||
|
|
||||||
|
\t;length: \c;\l;float\u cbot\float;\n;
|
||||||
|
Length of the move, in meters. A negative value makes the bot move backward.
|
||||||
|
|
||||||
|
\t;Return value: \c;\l;int\u cbot\int;\n;
|
||||||
|
Normally an error stops the program. You can prevent the program from stopping on errors by using the \c;\l;errmode\u cbot\errmode;(0)\n; instruction. A value different from zero if an error occurred is then returned by \c;move()\n;.
|
||||||
|
\c;== 0 \n;Move executed
|
||||||
|
\c;!= 0 \n;error, the instruction was not performed correctly
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,16 @@
|
||||||
|
\b;Type \c;nan\n;
|
||||||
|
This special value indicates that a \l;variable\u cbot\var; of type \c;\l;int\u cbot\int;\n; or \c;\l;float\u cbot\float;\n; contains no number, but "nothing".
|
||||||
|
For example, if the instruction \c;\l;receive\u cbot\receive;\n; can not get the requested information, it returns \c;nan\n; :
|
||||||
|
\c;
|
||||||
|
\s; value = receive("Length");
|
||||||
|
\s; if ( value == nan ) // not found ?
|
||||||
|
\s; {
|
||||||
|
\s;
|
||||||
|
\s; }
|
||||||
|
\n;
|
||||||
|
\t;Dictionnary
|
||||||
|
\c;nan\n; = Not A Number
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
\b;Instruction \c;new\n; (for specialists)
|
||||||
|
The \c;new\n; operator creates a \l;class\u cbot\class; instance:
|
||||||
|
\c;\s; MyClass item; // now item is a null reference
|
||||||
|
\s; item = new MyClass(); // now item is a reference
|
||||||
|
\s; // to a new class instance
|
||||||
|
\n;
|
||||||
|
If you want to create a new instance at declaration time you can ommit the new \c;new\n; operator by putting () after the declaration:
|
||||||
|
|
||||||
|
Instead of:
|
||||||
|
\c;\s; MyClass item = new MyClass();
|
||||||
|
\n;you can write:
|
||||||
|
\c;\s; MyClass item();
|
||||||
|
\n;
|
||||||
|
If your class has a constructor with parameters you can write:
|
||||||
|
\c;\s; MyClass item = new MyClass(2, 3);
|
||||||
|
\n;or:
|
||||||
|
\c;\s; MyClass item(2, 3);
|
||||||
|
\n;
|
||||||
|
\t;See also
|
||||||
|
\c;\l;class\u cbot\class;\n;, \c;\l;reference\u cbot\pointer;\n;
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,7 @@
|
||||||
|
\b;Type \c;null\n;
|
||||||
|
This special value indicates that the variable containing it does not reference an instance.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;References\u cbot\pointer;
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
\b;Type \c;object\n;
|
||||||
|
Use this type for variables that contain the characteristics of an object, be it a bot, a building, some raw material, an enemy, etc.
|
||||||
|
|
||||||
|
\c;\l;int\u cbot\int; object.category \n;\l;Category\u cbot\category; of the object
|
||||||
|
\c;\l;point\u cbot\point; object.position \n;Position of the object (x,y,z)
|
||||||
|
\c;\l;float\u cbot\float; object.orientation \n;Orientation of the object (0..360)
|
||||||
|
\c;\l;float\u cbot\float; object.pitch \n;Forward/backward angle of the object
|
||||||
|
\c;\l;float\u cbot\float; object.roll \n;Right/left angle of the object
|
||||||
|
\c;\l;float\u cbot\float; object.energyLevel \n;Energy level (0..1)
|
||||||
|
\c;\l;float\u cbot\float; object.shieldLevel \n;Shield level (0..1)
|
||||||
|
\c;\l;float\u cbot\float; object.temperature \n;Jet temperature (0..1)
|
||||||
|
\c;\l;float\u cbot\float; object.altitude \n;Altitude above ground
|
||||||
|
\c;\l;float\u cbot\float; object.lifeTime \n;Lifetime of the object
|
||||||
|
\c;object object.energyCell \n;Power cell on the bot
|
||||||
|
\c;object object.load \n;Object carried by the bot
|
||||||
|
|
||||||
|
\s;\c;category\n;
|
||||||
|
The \n;\l;category\u cbot\category; of an object allows you to know what it is, f. ex. what kind of bot, building, enemy, etc.
|
||||||
|
|
||||||
|
\s;\c;position\n;
|
||||||
|
Position of the object on the planet, in meters. The coordinates \c;x\n; and \c;y\n; correspond to the location on a map, the \c;z\n; coordinate corresponds to the altitude above (respectively below) sea level.
|
||||||
|
|
||||||
|
\s;\c;orientation\n;
|
||||||
|
Orientation of the object, in degrees. The orientation tells you what direction the object is facing. An orientation of \c;0\n; corresponds to an object facing eastwards, thus following the positive \c;x\n; axis. The orientation is measured counterclockwise.
|
||||||
|
|
||||||
|
\s;\c;pitch\n;
|
||||||
|
Forward/backward angle of the robot. A pitch of \c;0\n; means that the bot is standing on flat ground. A positive inclination means that it is facing upwards, a negative inclination means that it is facing downwards.
|
||||||
|
|
||||||
|
\s;\c;roll\n;
|
||||||
|
Left/right angle of the bot, in degrees. A positive value means that the bot is leaning to the left side, a negative value means that it is leaning to the right side.
|
||||||
|
|
||||||
|
\s;\c;energyLevel\n;
|
||||||
|
Energy level, between 0 and 1. A normal \l;power cell\u object\power; that is fully charged returns the value \c;1\n;. A \l;nuclear power cell\u object\atomic; never returns a value higher than 1, it just lasts longer. Attention: The energy level of a bot is always zero, because the energy is not contained in the bot, but in the power cell. To know the energy level of the power cell of a bot, you must write \c;energyCell.energyLevel\n;.
|
||||||
|
|
||||||
|
\s;\c;shieldLevel\n;
|
||||||
|
Shield level of a robot or building. A level \c;1\n; indicates that the shield is still perfect. Every time that the bot or building gets a bullet or collides with another object, the shield level decreases. When the level reaches \c;0\n;, the next bullet or collision will destroy the bot or building.
|
||||||
|
Bots can re-energize their shield on a \l;repair center\u object\repair;. The shield of a building is repaired if it lays inside the protection sphere of a \l;shielder\u object\botshld;.
|
||||||
|
|
||||||
|
\s;\c;temperature\n;
|
||||||
|
Temperature of the jet of \l;winged bots\u object\botgj;. \c;0\n; corresponds to a cold jet. When used, the temperature increases progressively. When it reaches the value \c;1\n;, the jet is overheated and stops working, until it cooled down a little.
|
||||||
|
|
||||||
|
\s;\c;altitude\n;
|
||||||
|
The \c;z\n; coordinate of the position indicates the altitude above sea level, whereas the \c;altitude\n; indicates the height above ground. This value is meaningful only for \l;winged bots\u object\botgj; and for \l;wasps\u object\wasp;. For all other objects, this value is zero.
|
||||||
|
|
||||||
|
\s;\c;lifeTime\n;
|
||||||
|
The age of the object in seconds since it's creation.
|
||||||
|
|
||||||
|
\s;\c;energyCell\n;
|
||||||
|
This information is special, because it returns the information about another object, in this case the power pack. This means that energyCell contains all the characteristics of a normal object, for example \c;category\n; (PowerCell or NuclearCell), \c;position\n; (the position of the cell), etc.
|
||||||
|
If you want to know the energy level of a robot, you must not check \c;energyLevel\n;, but \c;energyCell.energyLevel\n;.
|
||||||
|
If the bot has bot no power cell, \c;energyCell\n; returns \c;null\n;.
|
||||||
|
|
||||||
|
\s;\c;load\n;
|
||||||
|
This information also returns the description of a whole object: the description of the object carried by a \l;grabber\u object\botgr;. If it carries nothing, \c;load\n; returns \c;null\n;.
|
||||||
|
|
||||||
|
\b;Examples
|
||||||
|
The type \c;object\n; returns the special value \c;\l;null\u cbot\null;\n; when the object does not exist. For example:
|
||||||
|
\c;
|
||||||
|
\s; object a;
|
||||||
|
\s; a = radar(BotGrabberRoller);
|
||||||
|
\s; if ( a == null ) // object does not exist ?
|
||||||
|
\s; {
|
||||||
|
\s; }
|
||||||
|
\s; if ( a.position.z > 50 ) // is it on a mountain ?
|
||||||
|
\s; {
|
||||||
|
\s; }
|
||||||
|
\n;
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
\b;Instruction \c;open\n;
|
||||||
|
Open a text file in the files/ folder. This is a method of the \c;\l;file\u cbot\file;\n; class. This is the reason why we always write \c;handle.open()\n;¦:
|
||||||
|
\c;
|
||||||
|
\s; handle.open("test.txt", "w");
|
||||||
|
\n;
|
||||||
|
To open a file, proceed as follows¦:
|
||||||
|
\c;
|
||||||
|
\s; file handle();
|
||||||
|
\s; handle.open("filename", "w");
|
||||||
|
\s; handle.writeln("abc");
|
||||||
|
\s; handle.close();
|
||||||
|
\n;
|
||||||
|
\c;"r"\n; mode: open for reading.
|
||||||
|
\c;"w"\n; mode: open for writing.
|
||||||
|
|
||||||
|
Files can only be created and opened in the files/ folder which is located in the folder where Colobot has been installed. You cannot not create or open files that are located elsewhere than in the files/ folder.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\c;\l;file\u cbot\file;\n;, \c;\l;close\u cbot\close;\n;, \c;\l;readln\u cbot\readln;\n;, \c;\l;writeln\u cbot\writeln;\n; and \c;\l;eof\u cbot\eof;\n;.
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,11 @@
|
||||||
|
\b;Instruction \c;openfile\n;
|
||||||
|
\c;openfile();\n; opens an text file in the files/ folder. This is not a method of the \c;\l;file\u cbot\file;\n; class but openfile returne a \l;reference\u cbot\pointer; to a new instance of the file class. You must supply two parameters, the filename and the opening mode.
|
||||||
|
\c;
|
||||||
|
\s;file handle = openfile("filename", "r");
|
||||||
|
\n;
|
||||||
|
\c;"r"\n; mode: open for reading.
|
||||||
|
\c;"w"\n; mode: open for writing.
|
||||||
|
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,36 @@
|
||||||
|
\b;Type \c;point\n;
|
||||||
|
Variables of this type contain the coordinates of a point in space. This type is made of three values that represent the \c;x\n;, \c;y\n; and \c;z\n; coordinates.
|
||||||
|
\c;x\n; and \c;y\n; correspond to the place on the ground. The positive \c;x\n; axis faces towards east, the positive \c;y\n; axis faces towards north.
|
||||||
|
The \c;z\n; value corresponds to the altitude above sea level.
|
||||||
|
|
||||||
|
If you want to declare a variable of type point, you can write:
|
||||||
|
\c;
|
||||||
|
\s; point a (10, 20, 30);
|
||||||
|
\n;
|
||||||
|
You can also set the variable taking one value after another:
|
||||||
|
\c;
|
||||||
|
\s; point b;
|
||||||
|
\s; b.x = 10;
|
||||||
|
\s; b.y = 20;
|
||||||
|
\s; b.z = 30;
|
||||||
|
\n;
|
||||||
|
With these examples, the following \l;condition\u cbot\cond; is true:
|
||||||
|
\c;
|
||||||
|
\s; if ( a == b )
|
||||||
|
\s; {
|
||||||
|
\s; }
|
||||||
|
\n;
|
||||||
|
The following declaration :
|
||||||
|
\c;
|
||||||
|
\s; point c (4, 7);
|
||||||
|
\n;
|
||||||
|
Is equivalent to :
|
||||||
|
\c;
|
||||||
|
\s; point c;
|
||||||
|
\s; c.x = 4;
|
||||||
|
\s; c.y = 7;
|
||||||
|
\s; c.z = 0;
|
||||||
|
\n;
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,53 @@
|
||||||
|
\b;References (for specialists)
|
||||||
|
CBOT uses references for \l;classes\u cbot\class; and \l;arrays\u cbot\array;. Any class variable actually contains a reference to the instance. The instance actually contains the class fields. Several references can reference the same instance. A \c;\l;null\u cbot\null;\n; reference references nothing. You can compare an instance to a suitcase and a reference to a carrier. Each time we need a new suitcase we create a new instance with a carrier. But a suitcase can be carried by more than one carrier. A carrier who carries no suitcase is a \c;\l;null\u cbot\null;\n; reference.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
\c;\s;{
|
||||||
|
\s; MyClass item1(); // create a new instance
|
||||||
|
\s; // referenced by item1
|
||||||
|
\s; MyClass item2; // create a null reference
|
||||||
|
\s; item2 = item1; // copy the reference,
|
||||||
|
\s; // item2 and item1 now reference
|
||||||
|
\s; // the same instance
|
||||||
|
\s; item1.a = 12; // modifies the instance
|
||||||
|
\s; // referenced by item1 (and item2)
|
||||||
|
\s; message(item2.a);// displays 12
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
If you pass a \l;class\u cbot\class; instance as parameter to a function, the function only receives a reference to the instance. That means if you modify the instance in the function, the instance that has been specified by the caller will be actuallay modified.
|
||||||
|
|
||||||
|
\c;\s;void Test( MyClass item )
|
||||||
|
\s;{
|
||||||
|
\s; item.a = 12; // modify the original instance
|
||||||
|
\s; item = new MyClass(); // new local instance
|
||||||
|
\s; item.a = 33; // modifie the local instance
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
Calling the fucntion \c;Test()\n;¦:
|
||||||
|
\c;\s;{
|
||||||
|
\s; MyClass toto();
|
||||||
|
\s; Test(toto);
|
||||||
|
\s; message(toto.a); // displays 12
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
The instance containing the field \c;a = 33\n; is referenced only by the newly created instance \c;item\n; inside the fucntion \c;Test\n;. At the end of \c;Test\n; this newly created instance referenced by \c;item\n; is automatically deleted.
|
||||||
|
|
||||||
|
A function can return an instance¦:
|
||||||
|
\c;\s;MyClass Test2( )
|
||||||
|
\s;{
|
||||||
|
\s; MyClass item = new MyClass();
|
||||||
|
\s; item.x = 33;
|
||||||
|
\s; return item;
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
Call the function like this:
|
||||||
|
\c;\s;{
|
||||||
|
\s; MyClass toto;
|
||||||
|
\s; toto = Test2(); // toto will contain a reference to
|
||||||
|
\s; // the instance created by Test2()
|
||||||
|
\s; message(toto.a); // displays 33
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
\t;See also
|
||||||
|
\c;\l;class\u cbot\class;\n;, \c;\l;new\u cbot\new;\n;
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,19 @@
|
||||||
|
\b;Instruction \c;private\n; (for specialists)
|
||||||
|
\l;Class\u cbot\class; members can be \l;public\u cbot\public; (by default) or private. A member can be declared privat by putting \c;private\n; before the type declaration of the member. Private members are not accessible from outside the class definition.
|
||||||
|
\c;
|
||||||
|
\s;public class MyClass
|
||||||
|
\s;{
|
||||||
|
\s; int b; // public by défault
|
||||||
|
\s; public int a; // als public
|
||||||
|
\s; private point position; // privat
|
||||||
|
\s;}
|
||||||
|
\s;void Test()
|
||||||
|
\s;{
|
||||||
|
\s; MyClass item;
|
||||||
|
\s; item.a = item.b = 12; // ok
|
||||||
|
\s; message( item.position ); // this is an error
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
\t;See also
|
||||||
|
\c;\l;class\u cbot\class;\n;, \c;\l;public\u cbot\public;\n;
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,51 @@
|
||||||
|
\b;Instruction \c;public\n; (for specialists)
|
||||||
|
This instruction has two distinct purposes¦:
|
||||||
|
|
||||||
|
1) Make a function available to other bots.
|
||||||
|
2) Make a class member accessible from outside the class definition.
|
||||||
|
|
||||||
|
\b;Instruction \c;public\n; for functions
|
||||||
|
If you put \c;public\n; before a \l;function\u cbot\function; definition, you can make the function available to programs in other bots in the same mission.
|
||||||
|
|
||||||
|
For example in the first bot we would have¦:
|
||||||
|
\c;
|
||||||
|
\s;public void object::Segment(float dist, float angle)
|
||||||
|
\s;{
|
||||||
|
\s; move(dist);
|
||||||
|
\s; turn(angle);
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
And in another bot we would have¦:
|
||||||
|
\c;
|
||||||
|
\s;extern void object::Square( )
|
||||||
|
\s;{
|
||||||
|
\s; for ( int i=0 ; i<4 ; i++ )
|
||||||
|
\s; {
|
||||||
|
\s; Segment(10, 90);
|
||||||
|
\s; fire(1);
|
||||||
|
\s; }
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
If you have declared a function \c;public\n;, you cannot define a function with the same name and arguments in another bot of the same mission.
|
||||||
|
|
||||||
|
If a bot containing a \c;public\n; function is destroyed, the other bots that make use of this function will be stopped with an error.
|
||||||
|
|
||||||
|
\b;Instruction \c;public\n; for classes
|
||||||
|
\l;Class\u cbot\class; members can be public (by default) or \l;privat\u cbot\private;. A member can be declared private by putting \c;private\n; before the member type. Private members are not accessible from outside the class definition.
|
||||||
|
\c;
|
||||||
|
\s;public class MyClass
|
||||||
|
\s;{
|
||||||
|
\s; int b; // public by default
|
||||||
|
\s; public int a; // also public
|
||||||
|
\s; private point position; // privat
|
||||||
|
\s;}
|
||||||
|
\s;void Test()
|
||||||
|
\s;{
|
||||||
|
\s; MyClass item;
|
||||||
|
\s; item.a = item.b = 12; // ok
|
||||||
|
\s; message( item.position ); // this is an error
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
\t;See also
|
||||||
|
\c;\l;class\u cbot\class;\n;, \c;\l;private\u cbot\private;\n;, \c;\l;functions\u cbot\function;\n;
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,60 @@
|
||||||
|
\b;Instruction \c;radar\n;
|
||||||
|
With the instruction \c;radar()\n;, you can look for objects like \l;enemies\u object\mother;, bots, buildings or raw materials.
|
||||||
|
|
||||||
|
\b;Basic use
|
||||||
|
Write in brackets the \l;name of the object\u cbot\category; that you look for. Put the result in a variable of the \l;type\u cbot\type; \c;object\n;. Here is an example that looks for the closest ant:
|
||||||
|
\c;
|
||||||
|
\s;// At the beginning of the program:
|
||||||
|
\s;object item; // variable declaration
|
||||||
|
\s;
|
||||||
|
\s;// Look for the closest ant
|
||||||
|
\s;item = radar(AlienAnt);
|
||||||
|
\n;
|
||||||
|
\b;For specialists
|
||||||
|
Syntax:
|
||||||
|
\s;\c;radar ( category, angle, focus, min, max, way );\n;
|
||||||
|
|
||||||
|
Detects an object according to several parameters.
|
||||||
|
|
||||||
|
\image radar1 8 8;
|
||||||
|
Seen from above, the purple zone corresponds to the zone where objects will be detected.
|
||||||
|
|
||||||
|
\t;category: \c;\l;int\u cbot\int;\n;
|
||||||
|
\l;Category\u cbot\category; of the objects that should be detected. For example, when you are looking for an ant, write \c;radar (AlienAnt)\n;.
|
||||||
|
|
||||||
|
\t;angle: \c;\l;float\u cbot\float;\n; (default value\c;0\n;)
|
||||||
|
Direction that the radar is facing, in degrees.
|
||||||
|
\c; 0\n; -> radar is facing straight ahead
|
||||||
|
\c;-90\n; -> radar is facing a quarter turn right
|
||||||
|
\c; 90\n; -> radar is facing a quarter turn left
|
||||||
|
|
||||||
|
\t;focus: \c;\l;float\u cbot\float;\n; (default value\c;360\n;)
|
||||||
|
Opening angle of the radar, in degrees.
|
||||||
|
|
||||||
|
\t;min: \c;\l;float\u cbot\float;\n; (default value \c;0\n;)
|
||||||
|
Minimum detection distance, in meters. Objects that are closer than the minimum distance will not be detected.
|
||||||
|
|
||||||
|
\t;max: \c;\l;float\u cbot\float;\n; (Default value\c;1000\n;)
|
||||||
|
Maximum detection distance, in meters. Objects that are farther away than the maximum distance will not be detected.
|
||||||
|
|
||||||
|
\t;way: \c;\l;float\u cbot\float;\n; (default value\c;1\n;)
|
||||||
|
Determines which way the objects are detected. With value \c;1\n;, returns the closest object found in the specified zone. With value \c;-1\n;, the farthest object in the zone will be returned.
|
||||||
|
|
||||||
|
\t;Return value: \c;\l;object\u cbot\object;\n;
|
||||||
|
Returns the first object found that corresponds to the specified category in the specified zone. If no object was found, returns the value \c;\l;null\u cbot\null;\n;.
|
||||||
|
|
||||||
|
\t;Remark
|
||||||
|
You do not have to give all the parameters. Here are two examples of instructions that are equivalent:
|
||||||
|
\c;
|
||||||
|
\s; radar(Titanium, 0, 360, 0, 1000);
|
||||||
|
\s; radar(Titanium); // equivalent
|
||||||
|
|
||||||
|
\s; radar(Titanium, 0, 90, 0, 1000);
|
||||||
|
\s; radar(Titanium, 0, 90); // equivalent
|
||||||
|
\n;
|
||||||
|
When one or more parameters are not specified, the default values indicated above are used instead; only the first parameter is compulsory.
|
||||||
|
Generally, only the first parameter is specified: f. ex. \c;radar (AlienAnt)\n; detects the closest ant, wherever it may be.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
\b;Instruction \c;readln\n;
|
||||||
|
Read one line from an open file in the files/ folder. This is a method of the \c;\l;file\u cbot\file;\n; class. This is the reason why we always write \c;handle.readln()\n;¦:
|
||||||
|
\c;
|
||||||
|
\s; s = handle.readln();
|
||||||
|
\n;
|
||||||
|
The file must have been opened for reading (\c;"r"\n;) with the \c;\l;open\u cbot\open;\n; instruction. \c;readln\n; returns the string containing the whole line but without the end of line characters 0x0D (CR) and 0x0A (LF).
|
||||||
|
|
||||||
|
Syntax¦:
|
||||||
|
\s;\c;string = handle.readln ( );\n;
|
||||||
|
|
||||||
|
Example¦:
|
||||||
|
\c;
|
||||||
|
\s; string s;
|
||||||
|
\s; s = handle.readln();
|
||||||
|
\s; if ( s == "abc" )
|
||||||
|
\s; ...
|
||||||
|
\n;
|
||||||
|
\t;See also
|
||||||
|
\c;\l;file\u cbot\file;\n;, \c;\l;open\u cbot\open;\n;, \c;\l;close\u cbot\close;\n;, \c;\l;writeln\u cbot\writeln;\n; and \c;\l;eof\u cbot\eof;\n;.
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,18 @@
|
||||||
|
\b;Instruction \c;receive\n;
|
||||||
|
Syntax:
|
||||||
|
\s;\c;receive ( name, power );\n;
|
||||||
|
|
||||||
|
Retrieves an information from the closest \l;information exchange post\u object\exchange;.
|
||||||
|
|
||||||
|
\t;name: \c;string\n;
|
||||||
|
Name of the information required from the exchange post. This name is a string: it must be written in quotation marks "¦".
|
||||||
|
|
||||||
|
\t;power: \c;float\n;
|
||||||
|
Power of the receiver, which corresponds to maximal distance between the receiver and the exchange post. If the distance is longer, no information is received. Default value is 10 metres.
|
||||||
|
|
||||||
|
\t;Return value: \c;\l;float\u cbot\float;\n;
|
||||||
|
Value of the retrieved information. If no exchange post is close enough, or if the name of the requested information does not exist in the exchange post, the value \c;nan\n; is returned.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\c;\l;send\u cbot\send;\n;, \c;\l;testinfo\u cbot\testinfo;\n; and \c;\l;deleteinfo\u cbot\delinfo;\n;.
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,14 @@
|
||||||
|
\b;Instruction \c;recycle\n;
|
||||||
|
Syntax:
|
||||||
|
\s;\c;recycle ( );\n;
|
||||||
|
|
||||||
|
Recycles the derelict bot in front of the \l;recycler\u object\botrecy; into a \l;titanium cube\u object\titan;.
|
||||||
|
|
||||||
|
\t;Return value: \c;\l;int\u cbot\int;\n;
|
||||||
|
Zero if OK, or a value different from zero if an error occurred.
|
||||||
|
\c;== 0 \n;the derelict bot has been recycled
|
||||||
|
\c;!= 0 \n;error, no derelict bot could be recycled
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
\b;Instruction \c;retobject\n;
|
||||||
|
Syntax:
|
||||||
|
\s;\c;retobject ( number );\n;
|
||||||
|
|
||||||
|
Returns the object corresponding to the given number.
|
||||||
|
|
||||||
|
\t;number: \c;\l;int\u cbot\int;\n;
|
||||||
|
Number of the object, between 0 and n. "n" represents the total number of objects in the scene.
|
||||||
|
|
||||||
|
\t;Return value: \c;\l;object\u cbot\object;\n;
|
||||||
|
Object corresponding to the number. The return value \c;\l;null\u cbot\null;\n; means that no object corresponds to this number, because the number was too high, and there are not so many objects in the scene.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
\b;Instruction \c;return\n;
|
||||||
|
Returns from a function. Syntax:
|
||||||
|
\c;
|
||||||
|
\s;void function ( )
|
||||||
|
\s;{
|
||||||
|
\s; return;
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
\b;For specialists
|
||||||
|
If the \l;function\u cbot\function; has a return type, the \c;return\n; instruction must be followed by the value to be returned:
|
||||||
|
\c;
|
||||||
|
\s;float Pi ( )
|
||||||
|
\s;{
|
||||||
|
\s; return 3.1415;
|
||||||
|
\s;}
|
||||||
|
|
||||||
|
\s;float Mean (float a, float b)
|
||||||
|
\s;{
|
||||||
|
\s; return (a+b)/2;
|
||||||
|
\s;}
|
||||||
|
|
||||||
|
\s;string Sign (float a)
|
||||||
|
\s;{
|
||||||
|
\s; if ( a > 0 ) return "positive";
|
||||||
|
\s; if ( a < 0 ) return "négative";
|
||||||
|
\s; return "null";
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
\b;Instruction \c;search\n;
|
||||||
|
Syntax:
|
||||||
|
\s;\c;search ( category, position );\n;
|
||||||
|
|
||||||
|
Detects the object of the given category that is closest to the given position.
|
||||||
|
|
||||||
|
\t;category: \c;\l;int\u cbot\int;\n;
|
||||||
|
\l;Category\u cbot\category; of the requested object.
|
||||||
|
|
||||||
|
\t;position: \c;\l;point\u cbot\point;\n;
|
||||||
|
\c;search\n; returns the object of the given category that is closest to the position indicated here.
|
||||||
|
|
||||||
|
\t;Return value: \c;\l;object\u cbot\object;\n;
|
||||||
|
Characteristics of the object that has been found. The value \c;\l;null\u cbot\null;\n; means that no object of this category has been found.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
\b;Instruction \c;send\n;
|
||||||
|
Syntax¦:
|
||||||
|
\s;\c;send ( name, value, power );\n;
|
||||||
|
|
||||||
|
Sends an information to the closest \l;information exchange post\u object\exchange;.
|
||||||
|
|
||||||
|
\t;name: \c;string\n;
|
||||||
|
Name of the information to be sent to the exchange post. This name is a string: it must be written in quotation marks "¦".
|
||||||
|
If there is any information having this name, a new entry is created, as far as the total number of entries does not exceed 10. If there is already an information having this name, value is simply replaced by the new.
|
||||||
|
|
||||||
|
\t;value: \c;float\n;
|
||||||
|
Value of the information to be sent.
|
||||||
|
|
||||||
|
\t;power: \c;float\n;
|
||||||
|
Power of the transmitter, which corresponds to the maximal distance to where information can be the sent. Default value is 10 metres.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\c;\l;receive\u cbot\receive;\n;, \c;\l;testinfo\u cbot\testinfo;\n; and \c;\l;deleteinfo\u cbot\delinfo;\n;.
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,19 @@
|
||||||
|
\b;Instruction \c;shield\n;
|
||||||
|
Syntax:
|
||||||
|
\s;\c;shield ( oper );\n;
|
||||||
|
|
||||||
|
Activates or deactivates the shield of the \l;ahielder\u object\botshld;. You can of course move the shielder when the shield is active. It protects all objects that are inside the shielded sphere from enemy fire. The radius of the sphere can range between 10 and 25 meters.
|
||||||
|
|
||||||
|
\t;oper: \c;\l;float\u cbot\float;\n;
|
||||||
|
\c;1\n; activates the shield.
|
||||||
|
\c;0\n; deactivates the shield
|
||||||
|
A normal \l;power cell\u object\power; fully charged can maintain the shield active during 20 seconds. When the cell is empty, the shield deactivates.
|
||||||
|
|
||||||
|
\t;radius: \c;\l;float\u cbot\float;\n;
|
||||||
|
Radius of the shield, ranging between 10 and 25 meters.
|
||||||
|
|
||||||
|
\t;Return value: \c;\l;void\u cbot\void;\n;
|
||||||
|
None.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,22 @@
|
||||||
|
\b;Instruction \c;sizeof\n;
|
||||||
|
The sizeof function lets you know the number of elements contained in an \l;array\u cbot\array;.
|
||||||
|
That is the index of the last element plus one ("empty" elements are counted).
|
||||||
|
\c;
|
||||||
|
\s;{
|
||||||
|
\s; int a[12];
|
||||||
|
\s; a[5] = 345;
|
||||||
|
\s; message( sizeof(a) ); // will display 6
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
In this example we have 6 elements in the array after \c;a[5]=345\n;. The non initialized elements \c;[0]\n;, \c;[1]\n;, \c;[2]\n;, \c;[3]\n; and \c;[4]\n; will be counted.
|
||||||
|
|
||||||
|
With multidimensionnal arrays you can get the size of a sub array:
|
||||||
|
\c;
|
||||||
|
\s;float xy[][]; // 2 dimensionnal array
|
||||||
|
\s;xy[5][10] = 67;
|
||||||
|
\s;message( sizeof(xy) ); // will display 6
|
||||||
|
\s;message( sizeof(xy[5]) ); // will display 11
|
||||||
|
\s;
|
||||||
|
\n;
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,17 @@
|
||||||
|
\b;Instruction \c;sniff\n;
|
||||||
|
Syntax:
|
||||||
|
\s;\c;sniff ( );\n;
|
||||||
|
|
||||||
|
Sounds the underground in front of the \l;sniffer\u object\botsr;. According to what raw materials were detected, the following objects will be created:
|
||||||
|
|
||||||
|
\c;TitaniumSpot\n; -> \l;Red cross\u object\stonspot;
|
||||||
|
\c;UraniumSpot \n; -> \l;Yellow circle\u object\uranspot;
|
||||||
|
\c;PowerSpot \n; -> \l;Green cross\u object\enerspot;
|
||||||
|
|
||||||
|
\t;Return value: \c;\l;int\u cbot\int;\n;
|
||||||
|
Zero if everything is OK, or a value different from zero if an error occurred.
|
||||||
|
\c;== 0 \n;sounding performed
|
||||||
|
\c;!= 0 \n;sounding impossible
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,23 @@
|
||||||
|
\b;Instruction \c;space\n;
|
||||||
|
Syntax :
|
||||||
|
\s;\c;space ( center, rmin, rmax, dist );\n;
|
||||||
|
|
||||||
|
Determines the position of the nearest free space around a given position.
|
||||||
|
|
||||||
|
\t;center: \c;\l;point\u cbot\point;\n; (default: bot position)
|
||||||
|
Desired position of the free space.
|
||||||
|
|
||||||
|
\t;rmin: \c;\l;float\u cbot\float;\n; (default value: \c;8\n;)
|
||||||
|
Minimum distance from the desired position.
|
||||||
|
|
||||||
|
\t;rmax: \c;\l;float\u cbot\float;\n; (default value: \c;50\n;)
|
||||||
|
Maximum distance from the desired position.
|
||||||
|
|
||||||
|
\t;dist: \c;\l;float\u cbot\float;\n; (default value: \c;4\n;)
|
||||||
|
Required distance between two free spaces.
|
||||||
|
|
||||||
|
\t;Return: \c;\l;point\u cbot\point;\n;
|
||||||
|
Position of the free space.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,22 @@
|
||||||
|
\b;Instruction \c;static\n; (for specialists)
|
||||||
|
\l;Class\u cbot\class; members declared with \c;static\n; are shared between all instances of the class.
|
||||||
|
\c;
|
||||||
|
\s;public class MyClass
|
||||||
|
\s;{
|
||||||
|
\s; static int nb = 1;
|
||||||
|
\s; static string [ ] list = null;
|
||||||
|
\s;}
|
||||||
|
\s;void Test ()
|
||||||
|
\s;{
|
||||||
|
\s; MyClasse item1();
|
||||||
|
\s; MyClasse item2();
|
||||||
|
\s; item1.nb = 3;
|
||||||
|
\s; item1.list[item1.nb] = "Hello";
|
||||||
|
\s; message( item2.list[item2.nb] ); // display "Hello"
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
\c;Static\n; members can be declared \c;\l;private\u cbot\private;\n; so they will be only acessible from within class members (including constructors and destructors).
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\c;\l;class\u cbot\class;\n;, \c;\l;synchronized\u cbot\synchro;\n;
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,20 @@
|
||||||
|
\b;Instruction \c;strfind\n;
|
||||||
|
Find a substring in a string and returns the position of the first substring found or \l;nan\u cbot\nan; if the substring has not been found.
|
||||||
|
|
||||||
|
Syntax¦:
|
||||||
|
\s;\c;strfind ( string, sub );\n;
|
||||||
|
|
||||||
|
\t;string: \c;\l;string\u cbot\string;\n;
|
||||||
|
String we are searching in.
|
||||||
|
|
||||||
|
\t;sub: \c;\l;string\u cbot\string;\n;
|
||||||
|
Substring we are searching for.
|
||||||
|
|
||||||
|
Examples¦:
|
||||||
|
\s;\c; int pos = strfind("abcdef", "ab"); // pos will be 0
|
||||||
|
\s; int pos = strfind("abcdef", "de"); // pos will be 3
|
||||||
|
\s; int pos = strfind("abcdef", "xy"); // pos will be \l;nan\u cbot\nan;
|
||||||
|
\n;
|
||||||
|
\t;See also
|
||||||
|
\c;\l;strlen\u cbot\strlen;\n;, \c;\l;strleft\u cbot\strleft;\n;, \c;\l;strright\u cbot\strright;\n;, \c;\l;strmid\u cbot\strmid;\n;, \c;\l;strval\u cbot\strval;\n;, \c;\l;strupper\u cbot\strupper;\n;, \c;\l;strlower\u cbot\strlower;\n;
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,33 @@
|
||||||
|
\b;Type \c;string\n;
|
||||||
|
Use a variable of this type for storing characters or strings.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
\s;\c; "Hello!"
|
||||||
|
\s; "This is a string"
|
||||||
|
\s; "x"
|
||||||
|
\s; "" // empty string
|
||||||
|
\n;
|
||||||
|
You can append two strings with the \c;+\n; operator :
|
||||||
|
\s;\c; "Good morning," + " " + "Sir"
|
||||||
|
\n;
|
||||||
|
Returns the string:
|
||||||
|
\s;\c; "Good morning, Sir"
|
||||||
|
\n;
|
||||||
|
If you want to put a quotation mark (") or a backslash (\) in a string you must write¦:
|
||||||
|
\s;\c;"This is \"very\" important"
|
||||||
|
\n;which will result in the string \c; This is "very" important.
|
||||||
|
\s;\c;"%user%\\ant.txt"
|
||||||
|
\n;will result in \c;%user%\ant.txt
|
||||||
|
\n;
|
||||||
|
Following instructions can be used with strings¦:
|
||||||
|
\c;\l;strlen\u cbot\strlen; \n;Get string length
|
||||||
|
\c;\l;strleft\u cbot\strleft; \n;Extract left part
|
||||||
|
\c;\l;strright\u cbot\strright; \n;Extract right part
|
||||||
|
\c;\l;strmid\u cbot\strmid; \n;Extract center part
|
||||||
|
\c;\l;strfind\u cbot\strfind; \n;Find a substring.
|
||||||
|
\c;\l;strval\u cbot\strval; \n;Convert string to number
|
||||||
|
\c;\l;strupper\u cbot\strupper; \n;Convert to upper case
|
||||||
|
\c;\l;strlower\u cbot\strlower; \n;Convert to lower case
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,16 @@
|
||||||
|
\b;Instruction \c;strleft\n;
|
||||||
|
Extracts the first (that is, leftmost) characters from a string.
|
||||||
|
|
||||||
|
Syntax¦:
|
||||||
|
\s;\c;strleft ( string, len );\n;
|
||||||
|
|
||||||
|
\t;len: \c;\l;int\u cbot\int;\n;
|
||||||
|
Number of characters to be extracted.
|
||||||
|
|
||||||
|
Examples¦:
|
||||||
|
\s;\c; string s = strleft("abcdef", 2); // s is "ab"
|
||||||
|
\s; string s = strleft("abc", 10); // s is "abc"
|
||||||
|
\n;
|
||||||
|
\t;See also
|
||||||
|
\c;\l;strlen\u cbot\strlen;\n;, \c;\l;strright\u cbot\strright;\n;, \c;\l;strmid\u cbot\strmid;\n;, \c;\l;strfind\u cbot\strfind;\n;, \c;\l;strval\u cbot\strval;\n;, \c;\l;strupper\u cbot\strupper;\n;, \c;\l;strlower\u cbot\strlower;\n;
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,14 @@
|
||||||
|
\b;Instruction \c;strlen\n;
|
||||||
|
Get the length of a string.
|
||||||
|
|
||||||
|
Syntax¦:
|
||||||
|
\s;\c;strlen ( string );\n;
|
||||||
|
|
||||||
|
Examples¦:
|
||||||
|
\s;\c; int len = strlen("abc"); // len is 3
|
||||||
|
\s; int len = strlen(""); // len is 0
|
||||||
|
\s; if ( strlen(s) == 0 ) // is string empty ?
|
||||||
|
\n;
|
||||||
|
\t;See also
|
||||||
|
\c;\l;strleft\u cbot\strleft;\n;, \c;\l;strright\u cbot\strright;\n;, \c;\l;strmid\u cbot\strmid;\n;, \c;\l;strfind\u cbot\strfind;\n;, \c;\l;strval\u cbot\strval;\n;, \c;\l;strupper\u cbot\strupper;\n;, \c;\l;strlower\u cbot\strlower;\n;
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,12 @@
|
||||||
|
\b;Instruction \c;strlower\n;
|
||||||
|
Convert all characters in a string to lowercase.
|
||||||
|
|
||||||
|
Syntax¦:
|
||||||
|
\s;\c;strlower ( string );\n;
|
||||||
|
|
||||||
|
Examples¦:
|
||||||
|
\s;\c; string s = strlower("Abc"); // s is "abc"
|
||||||
|
\n;
|
||||||
|
\t;See also
|
||||||
|
\c;\l;strlen\u cbot\strlen;\n;, \c;\l;strleft\u cbot\strleft;\n;, \c;\l;strright\u cbot\strright;\n;, \c;\l;strmid\u cbot\strmid;\n;, \c;\l;strfind\u cbot\strfind;\n;, \c;\l;strval\u cbot\strval;\n;, \c;\l;strupper\u cbot\strupper;\n;
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,20 @@
|
||||||
|
\b;Instruction \c;strmid\n;
|
||||||
|
Extracts a substring of a given length starting at a given position from a string.
|
||||||
|
|
||||||
|
Syntax¦:
|
||||||
|
\s;\c;strmid ( string, pos, len );\n;
|
||||||
|
|
||||||
|
\t;pos: \c;\l;int\u cbot\int;\n;
|
||||||
|
The index of the first character that is to be included in the extracted substring.
|
||||||
|
|
||||||
|
\t;len: \c;\l;int\u cbot\int;\n;
|
||||||
|
Number of characters to be extracted.
|
||||||
|
|
||||||
|
Examples¦:
|
||||||
|
\s;\c; string s = strmid("abcdef", 1, 2); // s is "bc"
|
||||||
|
\s; string s = strmid("abcdef", 4, 5); // s is "ef"
|
||||||
|
\s; string s = strmid("abcdef", 9, 2); // s is ""
|
||||||
|
\n;
|
||||||
|
\t;See also
|
||||||
|
\c;\l;strlen\u cbot\strlen;\n;, \c;\l;strleft\u cbot\strleft;\n;, \c;\l;strright\u cbot\strright;\n;, \c;\l;strfind\u cbot\strfind;\n;, \c;\l;strval\u cbot\strval;\n;, \c;\l;strupper\u cbot\strupper;\n;, \c;\l;strlower\u cbot\strlower;\n;
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,16 @@
|
||||||
|
\b;Instruction \c;strright\n;
|
||||||
|
Extracts the last (that is, rightmost) characters from a string.
|
||||||
|
|
||||||
|
Syntax¦:
|
||||||
|
\s;\c;strright ( string, len );\n;
|
||||||
|
|
||||||
|
\t;len: \c;\l;int\u cbot\int;\n;
|
||||||
|
Number of characters to be extracted.
|
||||||
|
|
||||||
|
Examples¦:
|
||||||
|
\s;\c; string s = strright("abcdef", 2); // s is "ef"
|
||||||
|
\s; string s = strright("abc", 10); // s is "abc"
|
||||||
|
\n;
|
||||||
|
\t;See also
|
||||||
|
\c;\l;strlen\u cbot\strlen;\n;, \c;\l;strleft\u cbot\strleft;\n;, \c;\l;strmid\u cbot\strmid;\n;, \c;\l;strfind\u cbot\strfind;\n;, \c;\l;strval\u cbot\strval;\n;, \c;\l;strupper\u cbot\strupper;\n;, \c;\l;strlower\u cbot\strlower;\n;
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,12 @@
|
||||||
|
\b;Instruction \c;strupper\n;
|
||||||
|
Convert all characters in a string to uppercase.
|
||||||
|
|
||||||
|
Syntax¦:
|
||||||
|
\s;\c;strupper ( string );\n;
|
||||||
|
|
||||||
|
Examples¦:
|
||||||
|
\s;\c; string s = strupper("Abc"); // s is "ABC"
|
||||||
|
\n;
|
||||||
|
\t;See also
|
||||||
|
\c;\l;strlen\u cbot\strlen;\n;, \c;\l;strleft\u cbot\strleft;\n;, \c;\l;strright\u cbot\strright;\n;, \c;\l;strmid\u cbot\strmid;\n;, \c;\l;strfind\u cbot\strfind;\n;, \c;\l;strval\u cbot\strval;\n;, \c;\l;strlower\u cbot\strlower;\n;
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,19 @@
|
||||||
|
\b;Instruction \c;strval\n;
|
||||||
|
Convert a string to a number. Don't confuse the string \c;"45"\n; that contains actually the two characters \c;4\n; and \c;5\n; and the number \c;45\n;.
|
||||||
|
|
||||||
|
Examples¦:
|
||||||
|
\s;\c; string s = "45"+"12"; // s contains "4512"
|
||||||
|
\s; float n = 45 + 12; // n contains 67
|
||||||
|
\n;
|
||||||
|
Syntax¦:
|
||||||
|
\s;\c;strval ( string );\n;
|
||||||
|
\n;
|
||||||
|
Examples¦:
|
||||||
|
\s;\c; float n = strval("1.23"); // n is 1.23
|
||||||
|
\s; float n = strval("12abc45"); // n is 12
|
||||||
|
\s; float n = strval("abc"); // n is 0
|
||||||
|
\s; float n = strval("100")+2; // n is 102
|
||||||
|
\n;
|
||||||
|
\t;See also
|
||||||
|
\c;\l;strlen\u cbot\strlen;\n;, \c;\l;strleft\u cbot\strleft;\n;, \c;\l;strright\u cbot\strright;\n;, \c;\l;strmid\u cbot\strmid;\n;, \c;\l;strfind\u cbot\strfind;\n;, \c;\l;strupper\u cbot\strupper;\n;, \c;\l;strlower\u cbot\strlower;\n;
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,25 @@
|
||||||
|
\b;Instruction \c;synchronized\n; (for specialists)
|
||||||
|
A \l;class\u cbot\class; method can be declared \c;synchronized\n;. This is to make sure that the method is never being executed by more than one bot at the same time.
|
||||||
|
|
||||||
|
The following example illustrates the problem:
|
||||||
|
\c;
|
||||||
|
\s;class blocking
|
||||||
|
\s;{
|
||||||
|
\s; static int nb = 33;
|
||||||
|
\s; synchronized int inc( )
|
||||||
|
\s; {
|
||||||
|
\s; int val = nb;
|
||||||
|
\s; wait ( 2 ); // wait 2 sec.
|
||||||
|
\s; nb = nb + 1;
|
||||||
|
\s; return val;
|
||||||
|
\s; }
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
What happens if two bots execute the \c;inc\n; method at the same time¦?
|
||||||
|
Both of them will execute \c;val=nb\n; and wait 2 seconds so both of them will have \c;val=33\n;. With \c;synchronized\n; the first bot starts execution with \c;val=33\n; and then waits 2 seconds and returns. Only once the first bot has returned from the \c;inc\n; method, the second bot will be allowed to enter the \c;inc\n; method and therefore the second bot will always have \c;val=34\n;.
|
||||||
|
|
||||||
|
You can have more than one synchronized method in your \l;class\u cbot\class; in order to prevent simultaneous execution across more than one method. In other words: as long as a bot's program is inside a synchronized method, no other bot can enter any synchronized method of the same class.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\c;\l;class\u cbot\class;\n;, \c;\l;static\u cbot\static;\n;
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,31 @@
|
||||||
|
\b;Semicolon
|
||||||
|
Always use a semicolon \c;;\n; after a simple expression. For example:
|
||||||
|
\c;
|
||||||
|
\s; int counter = 0;
|
||||||
|
\n;
|
||||||
|
However, after a \l;bloc\u cbot\bloc;, never put a semicolon:
|
||||||
|
\c;
|
||||||
|
\s; {
|
||||||
|
\s; float dist;
|
||||||
|
\s; dist = distance(p1, p2);
|
||||||
|
\s; } \n;// no semicolon here!\c;
|
||||||
|
\n;
|
||||||
|
Do not use a semicolon either immediately after the instructions \c;\l;while\u cbot\while;\n;, \c;\l;if\u cbot\if;\n; or \c;\l;for\u cbot\for;\n;:
|
||||||
|
\c;
|
||||||
|
\s; if ( a < b ) \n;// no semicolon here!\c;
|
||||||
|
\s; {
|
||||||
|
\s; b = 100-a;
|
||||||
|
\s; }
|
||||||
|
\n;
|
||||||
|
An instruction is always ended by a semicolon, and not by the end of the line. So you can very well put several instructions on the same line:
|
||||||
|
\c;
|
||||||
|
\s; int d=20;
|
||||||
|
\s; move(d);
|
||||||
|
\s; turn(90);
|
||||||
|
\n;
|
||||||
|
Is equivalent to:
|
||||||
|
\c;
|
||||||
|
\s; int d=20; move(d); turn(90);
|
||||||
|
\n;
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,18 @@
|
||||||
|
\b;Instruction \c;testinfo\n;
|
||||||
|
Syntax¦:
|
||||||
|
\s;\c;testinfo ( name, power );\n;
|
||||||
|
|
||||||
|
Tests if an information exists in the closest \l;information exchange post\u object\exchange;.
|
||||||
|
|
||||||
|
\t;name: \c;string\n;
|
||||||
|
Name of the information to be tested in the exchange post. This name is a string: it must be written in quotation marks "¦".
|
||||||
|
|
||||||
|
\t;power: \c;float\n;
|
||||||
|
Power of the transmitter, which corresponds to the maximal distance between the transmitter and the exchange post. If the distance is longer, the function returns \c;false\n;. Default value is 10 metres.
|
||||||
|
|
||||||
|
\t;Return: \c;\l;bool\u cbot\bool;\n;
|
||||||
|
Return \c;true\n; if the information exists. Return and \c;false\n; if the information does not exist or if the receiver is too far away from the exchange post.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\c;\l;receive\u cbot\receive;\n;, \c;\l;send\u cbot\send;\n; and \c;\l;deleteinfo\u cbot\delinfo;\n;.
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,54 @@
|
||||||
|
\b;Instruction \c;this\n;
|
||||||
|
Occasionally, a \l;class\u cbot\class; method needs to know the reference to the instance it is acting upon. For example the instance might want to pass it's own reference to another function. An implicit reference name \c;this\n; is available to methods and \c;this\n; is a reference to the current instance.
|
||||||
|
\c;
|
||||||
|
\s;public class MyClass
|
||||||
|
\s;{
|
||||||
|
\s; int m_int;
|
||||||
|
\s; string m_str;
|
||||||
|
\s; void MyFunction()
|
||||||
|
\s; {
|
||||||
|
\s; OtherFunction(this);
|
||||||
|
\s; m_int = 2;
|
||||||
|
\s; }
|
||||||
|
\s;}
|
||||||
|
\s;
|
||||||
|
\s;void OtherFunction(MyClass obj)
|
||||||
|
\s;{
|
||||||
|
\s; message(obj.m_str);
|
||||||
|
\s;}
|
||||||
|
\s;
|
||||||
|
\s;extern void object::Test()
|
||||||
|
\s;{
|
||||||
|
\s; MyClass item();
|
||||||
|
\s; item.m_str = "Hello";
|
||||||
|
\s; item.MyFunction(); // display "Hello"
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
You can also put \c;this\n; before a field name in a method but this is not necessary. In the example above in the method \c;MyFunction()\n; following two lines have strictly the same meaning:
|
||||||
|
\c;
|
||||||
|
\s; m_int = 2;
|
||||||
|
\s; this.m_int = 2; // identical
|
||||||
|
\n;
|
||||||
|
In a method of the \c;\l;object\u cbot\object;\n; class, you can also use \c;this.\n; before a fieldname.
|
||||||
|
\c;
|
||||||
|
\s;extern void object::Display()
|
||||||
|
\s;{
|
||||||
|
\s; message(orientation);
|
||||||
|
\s; message(this.orientation); // same thing but
|
||||||
|
\s; // more explicit
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
However if a field name is hidden by a parameter declaration or a variable declaration you must use \c;this\n;. In the following example the name \c;value\n; of the parameter is the same as the name of the field \c;value\n; of the \l;class\u cbot\class; \c;MyClass\n;, we must therefore write \c;this.value\n; in order to distinguish the field from the parameter.
|
||||||
|
\c;
|
||||||
|
\s;public class MyClass
|
||||||
|
\s;{
|
||||||
|
\s; int value;
|
||||||
|
\s; void Put( int value )
|
||||||
|
\s; {
|
||||||
|
\s; this.value = value;
|
||||||
|
\s; }
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
\t;See also
|
||||||
|
\c;\l;class\u cbot\class;\n;
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; et \l;catégories\u cbot\category;.
|
|
@ -0,0 +1,13 @@
|
||||||
|
\b;Instruction \c;thump\n;
|
||||||
|
Syntax:
|
||||||
|
\s;\c;thump ( );\n;
|
||||||
|
|
||||||
|
Activates the weapon system of the \l;thumper\u object\bottump;, that turns ants and spiders belly up and makes them completely harmless for a while.
|
||||||
|
|
||||||
|
\t;Return value: \c;\l;int\u cbot\int;\n;
|
||||||
|
Zero if everything is OK, a value different from zero if an error occurred.
|
||||||
|
\c;== 0 \n;Thumping performed
|
||||||
|
\c;!= 0 \n;Operation impossible
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,14 @@
|
||||||
|
\b;Instruction \c;topo\n;
|
||||||
|
Syntax:
|
||||||
|
\s;\c;topo ( position );\n;
|
||||||
|
|
||||||
|
Returns the altitude of the ground at a give position. The altitude zero corresponds to sea level. A negative value indicates that at this position ground is covered with water.
|
||||||
|
|
||||||
|
\t;position: \c;\l;point\u cbot\point;\n;
|
||||||
|
Coordinates of the position whose altitude you want to know.
|
||||||
|
|
||||||
|
\t;Return value: \c;\l;float\u cbot\float;\n;
|
||||||
|
Altitude of the ground at the given position.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,5 @@
|
||||||
|
\b;Type \c;true\n;
|
||||||
|
This value means that a condition is true; it is one of the two values that a \l;boolean\u cbot\bool; \l;variable\u cbot\var; can take.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,33 @@
|
||||||
|
\b;Instruction \c;turn\n;
|
||||||
|
Use the instruction \c;turn();\n; to instruct the bot to perform a rotation on itself of a certain number of degrees.
|
||||||
|
|
||||||
|
\b;Basic use
|
||||||
|
90 degreed means a quarter turn, 180 degrees means a half turn. A positive angle will perform a counterclockwise rotation, a negative angle means a clockwise rotation. Here are some examples with \c;turn();\n;:
|
||||||
|
|
||||||
|
\c;turn(90);\n; quarter turn to the left
|
||||||
|
\c;turn(-90);\n; quarter turn to the right (negative angle)
|
||||||
|
\c;turn(180);\n; half turn
|
||||||
|
|
||||||
|
In order to turn the bot towards an object found with the instruction \c;\l;radar\u cbot\radar;();\n;, you must calculate the rotation angle with the instruction \c;\l;direction\u cbot\direct;()\n;:
|
||||||
|
\c;
|
||||||
|
\s; item = \l;radar\u cbot\radar;(AlienSpider);
|
||||||
|
\s; turn(\l;direction\u cbot\direct;(item.position));
|
||||||
|
\n;
|
||||||
|
After these lines, just fire the cannon, and there is one hostile element less.
|
||||||
|
|
||||||
|
\b;For specialists
|
||||||
|
Syntax:
|
||||||
|
\s;\c;turn ( angle );\n;
|
||||||
|
|
||||||
|
Turns the bot with a given angle, right or left, without moving either forward or backward.
|
||||||
|
|
||||||
|
\t;angle: \c;\l;float\u cbot\float;\n;
|
||||||
|
Angle of the required rotation, in degrees. A positive value turns left, a negative value turns right. \c;turn(180)\n; turns round completely.
|
||||||
|
|
||||||
|
\t;Return value: \c;\l;int\u cbot\int;\n;
|
||||||
|
Zero if everything is OK, or a value different from zero if an error occurred.
|
||||||
|
\c;== 0 \n;rotation performed
|
||||||
|
\c;!= 0 \n;rotation impossible
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,33 @@
|
||||||
|
\b;Variable types
|
||||||
|
When you define a \l;variable\u cbot\var;, you must give two elements:
|
||||||
|
|
||||||
|
1) a name
|
||||||
|
2) a type
|
||||||
|
|
||||||
|
Once you defined a variable, you can use it to put information in it. However, the information that a variable can contain must always be of the correct type: a variable of type \l;float\u cbot\float; can not contain a string, etc.
|
||||||
|
|
||||||
|
In a program, the name of a type is always written on \type;green background\norm;. If the name of a type is not colored, this means that the name is misspelled. Type names are always written with lower case characters. Here is a list of the different types:
|
||||||
|
|
||||||
|
\s;\c;\l;int\u cbot\int;\n;
|
||||||
|
For a whole number (12, -500, etc.).
|
||||||
|
|
||||||
|
\s;\c;\l;float\u cbot\float;\n;
|
||||||
|
For a real number (12, 3.14, 0.2, -99.98, etc.).
|
||||||
|
|
||||||
|
\s;\c;\l;bool\u cbot\bool;\n;
|
||||||
|
For a boolean variable, that can only take the values \c;true\n; or \c;false\n;.
|
||||||
|
|
||||||
|
\s;\c;\l;string\u cbot\string;\n;
|
||||||
|
For texts ("Hello!", "No object found", etc.)
|
||||||
|
|
||||||
|
\s;\c;\l;point\u cbot\point;\n;
|
||||||
|
For the coordinates of a point in space; a variable of this type consists of three parts named x, y and z.
|
||||||
|
|
||||||
|
\s;\c;\l;object\u cbot\object;\n;
|
||||||
|
A variable of this type contains the information about an object (bot, building, enemy, etc.).
|
||||||
|
|
||||||
|
\s;\c;\l;void\u cbot\void;\n;
|
||||||
|
This type is an "empty type", that you use when you do not want to specify a type.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,67 @@
|
||||||
|
\b;Variables
|
||||||
|
A variable is like a box, where you can put some information. The content of the variable can change during the execution of the program.
|
||||||
|
|
||||||
|
For example, you can use a variable to count the number of titanium ore units that the grabber has collected and carried to the converter. First, you must find a name for it: the name should not be too long, but explain by itself what the variable is used for. Let's call it \c;countTit\n;. This variable must contain only whole numbers, so choose the type \c;int\n;. At the beginning of the program, you must declare the variable. Then you put the value \c;0\n; into the variable, and every time you grab a titanium ore, you increase the variable by \c;1\n;. At every moment, the variable contains the number of titanium ore units that the grabber collected.
|
||||||
|
|
||||||
|
For the declaration of the variable, write the following line:
|
||||||
|
\c;\s; int countTit;\n;
|
||||||
|
|
||||||
|
To put \c;0\n; into the variable, write:
|
||||||
|
\c;\s; countTit = 0;\n;
|
||||||
|
|
||||||
|
At every titanium ore grabbed, write:
|
||||||
|
\c;\s; countTit = countTit + 1\n;
|
||||||
|
|
||||||
|
You have much freedom in the choice of the name for a variable, you can call them by any name, f. ex.: \c;dist\n;, \c;direct\n;, \c;p2\n;, \c;a\n;, \c;x\n;, \c;nothing_2_shoot_at\n;, etc.
|
||||||
|
A variable name must always begin with a letter. It can be followed by any combination of letters, digits or the underscore character \c;_\n;. You can of course not use the keywords of the CBOT language like \c;\l;for\u cbot\for;\n;, \c;\l;while\u cbot\while;\n;, \c;\l;break\u cbot\break;\n;, \c;\l;continue\u cbot\continue;\n;, \c;do\n;, etc.
|
||||||
|
You should be careful about the choice of the names that you give to variables; writing a program can become very difficult if you forget the names of variables or if you do not remember what they are used for. Elaborate your own system to find variable names, and do not use names like \c;Bmo45\n;, \c;a\n; or \c;tgBinX\n;.
|
||||||
|
|
||||||
|
In the example above, the keyword \c;int\n; indicates that this variable can contain only whole numbers, which is adequate to counting objects. If you want to measure a distance, better use a variable that can contain also real numbers, with a fractional part (like 3.45 or 0.034): in this case, use the type \c;float\n;.
|
||||||
|
|
||||||
|
In fact, a variable is made up of three parts:
|
||||||
|
1) the name
|
||||||
|
2) the type of the information stored inside
|
||||||
|
3) the content, i.e. the information itself
|
||||||
|
|
||||||
|
\t;the name
|
||||||
|
You need the name to be able to distinguish the different variables from each other.
|
||||||
|
|
||||||
|
\t;the type
|
||||||
|
The \l;type\u cbot\type; determines what kind of information the variable can contain. According to the type, a variable can contain a whole number, a real number, a string, the coordinates of a point, information about an object, etc.
|
||||||
|
Here is a list of the most common variable types:
|
||||||
|
o \c;\l;int\u cbot\int;\n; for a whole number (12, -500, etc.)
|
||||||
|
o \c;\l;float\u cbot\float;\n; for a real number (3.14, 0.2, -99.98, etc.)
|
||||||
|
o \c;\l;string\u cbot\string;\n; for a character string ("Hello!", "No object found", etc.)
|
||||||
|
o \c;\l;point\u cbot\point;\n; for a x,y,z-coordinate in space
|
||||||
|
o \c;\l;object\u cbot\object;\n; for information about an object (bot, building, etc.)
|
||||||
|
|
||||||
|
\t;The content
|
||||||
|
The content of a variable is an information of the kind specified in the type. It can change during the execution of the program.
|
||||||
|
|
||||||
|
Once you declared a variable, it still does not contain any value. Before you can use it, you must put a value inside:
|
||||||
|
\c;\s; int i, j;
|
||||||
|
\s; j = 25; // j takes the value 25
|
||||||
|
\s; j = i; // can not write this, because i has got no content yet.
|
||||||
|
\n;
|
||||||
|
You can also declare a variable and put a value inside in the same line, writing:
|
||||||
|
\c;\s; int countTit = 0;
|
||||||
|
\n;
|
||||||
|
When you assign a value to a variable with the equals sign \c;=\n;, the value on the right side is copied into the value on the left side. Consider the following example:
|
||||||
|
\c;\s; int i, j;
|
||||||
|
\s; i = 5+2; // i takes the value 7
|
||||||
|
\s; j = i+6; // j takes the value of i plus 6, this is 13
|
||||||
|
\s; i = j; // i takes the value of j, this is 13
|
||||||
|
\n;
|
||||||
|
At the end of this example, both variables \c;i\n; and \c;j\n; contain the value \c;13\n;.
|
||||||
|
|
||||||
|
The following assignment is not correct, because on the left side of the equals sign \c;=\n;, there can be only a variable name:
|
||||||
|
\c;\s; i+2 = j; // impossible
|
||||||
|
\n;
|
||||||
|
If you want to exchange the values of two variables, you must use a third variable. Here is an example to exchange the content of two variables \c;a\n; and \c;b\n; :
|
||||||
|
\c;\s; int temp;
|
||||||
|
\s; temp = a; // temp takes the value of a
|
||||||
|
\s; a = b; // the content of b is copied into a
|
||||||
|
\s; b = temp; // the content of temp is copied into b
|
||||||
|
\n;
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,11 @@
|
||||||
|
\b;Type \c;void\n;
|
||||||
|
Use this type when you want to declare a function that returns nothing.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
\c;\s;void MyFunction(int a)
|
||||||
|
\s;{
|
||||||
|
\s; ...
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,22 @@
|
||||||
|
\b;Instruction \c;wait\n;
|
||||||
|
The instruction \c;wait();\n; instructs the bot to wait for some seconds, according to the value written in brackets.
|
||||||
|
|
||||||
|
\b;Basic use
|
||||||
|
In order to wait until the \l;power cell\u object\power; is recharged on a power station, wait 5 seconds with \c;wait(5);\n;.
|
||||||
|
|
||||||
|
In order to wait until the \l;converter\u object\convert; finished transforming some \l;titanium ore\u object\titanore; in a \l;titanium cube\u object\titan;, wait 15 seconds with \c;wait(15);\n;.
|
||||||
|
|
||||||
|
\b;For specialists
|
||||||
|
Syntax:
|
||||||
|
\s;\c;wait ( time );\n;
|
||||||
|
|
||||||
|
Waits for a moment.
|
||||||
|
|
||||||
|
\t;time: \c;\l;float\u cbot\float;\n;
|
||||||
|
Specifies the time that the bot must wait.
|
||||||
|
|
||||||
|
\t;Return value: \c;\l;void\u cbot\void;\n;
|
||||||
|
None.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,47 @@
|
||||||
|
\b;Instruction \c;while\n;
|
||||||
|
The instruction \c;while () {}\n; is used to repeat a set of instructions several times.
|
||||||
|
|
||||||
|
\b;Basic use
|
||||||
|
The most frequent use of \c;while\n; consists in repeating a set of instructions again and again. In order to achieve this, write \c;while (true) {}\n; and put the instructions to be repeated in braces \c;{}\n;. As an example, here is a program that repeats again and again the following actions:
|
||||||
|
o look for a spider,
|
||||||
|
o turn towards it,
|
||||||
|
o shoot.
|
||||||
|
\c;
|
||||||
|
\s; while (true)
|
||||||
|
\s; {
|
||||||
|
\s; item = \l;radar\u cbot\radar;(AlienSpider);
|
||||||
|
\s; \l;turn\u cbot\turn;(direction(item.position));
|
||||||
|
\s; \l;fire\u cbot\fire;(1);
|
||||||
|
\s; }
|
||||||
|
\n;
|
||||||
|
Just execute this program once, and it will kill all spiders around it.
|
||||||
|
|
||||||
|
\b;For specialists
|
||||||
|
Syntax :
|
||||||
|
\s;\c;while ( condition )
|
||||||
|
\s;{
|
||||||
|
\s; \n;Instructions ...\c;
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
This instruction allows you to perform the instructions inside the \l;block\u cbot\bloc; several times.
|
||||||
|
|
||||||
|
Be careful not to confuse the instruction \c;while( ) { }\n; with the instruction \c;\l;do\u cbot\do; { } while( );\n;; the latter tests the condition only after the instructions in the block have been performed a first time.
|
||||||
|
|
||||||
|
\t;\c;condition\n;
|
||||||
|
The instructions in the block are performed over and over again, as long as the \l;condition\u cbot\cond; is true.
|
||||||
|
|
||||||
|
Here is an example :
|
||||||
|
\s;\c;int i = 0;
|
||||||
|
\s;while ( i < 10 )
|
||||||
|
\s;{
|
||||||
|
\s; \n;Instructions ...\c;
|
||||||
|
\s; i = i+1;
|
||||||
|
\s;}
|
||||||
|
\n;
|
||||||
|
\t;Attention
|
||||||
|
Do not put a \l;semicolon\u cbot\term; at the end of the line \c;while ( )\n;.
|
||||||
|
|
||||||
|
The instructions \c;\l;break\u cbot\break;\n; and \c;\l;continue\u cbot\continue;\n; can be useful inside a block following the instruction \c;while { }\n;.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Instructions\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,21 @@
|
||||||
|
\b;Instruction \c;writeln\n;
|
||||||
|
Write one line of text to an open file in the files/ folder. This is a method of the \c;\l;file\u cbot\file;\n; class. This is the reason why we always write \c;handle.writeln()\n;¦:
|
||||||
|
\c;
|
||||||
|
\s; handle.writeln("abc");
|
||||||
|
\n;
|
||||||
|
The file must have been opened for writing (\c;"w"\n;) with the \c;\l;open\u cbot\open;\n; instruction. The line will automatically be terminated by the end of line characters 0x0D (CR) and 0x0A (LF).
|
||||||
|
|
||||||
|
Syntax¦:
|
||||||
|
\s;\c;handle.writeln ( string );\n;
|
||||||
|
|
||||||
|
Examples¦:
|
||||||
|
\c;
|
||||||
|
\s; writeln("Line of text");
|
||||||
|
|
||||||
|
\s; string s1 = "abc";
|
||||||
|
\s; string s2 = "def";
|
||||||
|
\s; writeln(s1 + " " + s2);
|
||||||
|
\n;
|
||||||
|
\t;See also
|
||||||
|
\c;\l;file\u cbot\file;\n;, \c;\l;open\u cbot\open;\n;, \c;\l;close\u cbot\close;\n;, \c;\l;readln\u cbot\readln;\n; and \c;\l;eof\u cbot\eof;\n;.
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,45 @@
|
||||||
|
\b;Controls
|
||||||
|
You are advised to play with one hand on the arrow keys and the other hand on the mouse.
|
||||||
|
|
||||||
|
\t;Bots
|
||||||
|
\key;\key left;\norm; = turn left
|
||||||
|
\key;\key right;\norm; = turn right
|
||||||
|
\key;\key up;\norm; = move forward
|
||||||
|
\key;\key down;\norm; = move back
|
||||||
|
These controls are unavailable when working with the \l;practice bots\u object\bottr;.
|
||||||
|
|
||||||
|
\key;\key gup;\norm; = take off and climb \button 28;
|
||||||
|
\key;\key gdown;\norm; = descend and land \button 29;
|
||||||
|
These controls are of course restricted to the \l;astronaut\u object\human; as well as the various \l;winged bots\u object\botgj; and in selected missions only.
|
||||||
|
|
||||||
|
mouse forward = higher aim
|
||||||
|
mouse backward = lower aim
|
||||||
|
mouse right = aim right
|
||||||
|
mouse left = aim left
|
||||||
|
These controls are only available to the \l;shooters\u object\botfr;, the \l;orga shooters\u object\botor; and the \l;phazer shooter\u object\botphaz;.
|
||||||
|
|
||||||
|
\key;\key action;\norm; = main action for a given selection (human or bot)
|
||||||
|
This control will for example operate the arm of a \l;grabber\u object\botgr; or fire a \l;shooter\u object\botfr; \button 42;.
|
||||||
|
|
||||||
|
\t;Selections
|
||||||
|
\key;\key next;\norm; = selects next object
|
||||||
|
\key;\key human;\norm; = selects astronaut
|
||||||
|
\key;\key desel;\norm; = previous selection \button 10;
|
||||||
|
|
||||||
|
\t;Camera
|
||||||
|
\key;\key camera;\norm; = shifts between onboard and following cameras \button 13;
|
||||||
|
\key;\key near;\norm; = zoom in
|
||||||
|
\key;\key away;\norm; = zoom out
|
||||||
|
\key;\key visit;\norm; = pauses the game and shows where the latest message originated. Press again to show origin of previous message.
|
||||||
|
|
||||||
|
\t;Help
|
||||||
|
\key;\key help;\norm; = mission instructions
|
||||||
|
\key;\key prog;\norm; = programming help
|
||||||
|
|
||||||
|
\t;Game
|
||||||
|
\key;\key speed10;\norm; = normal speed x1
|
||||||
|
\key;\key speed15;\norm; = medium speed x1.5
|
||||||
|
\key;\key speed20;\norm; = faster speed x2
|
||||||
|
\key;\key quit;\norm; = exits mission \button 11;
|
||||||
|
|
||||||
|
All these commands can be redefined in the options/controls menu.
|
|
@ -0,0 +1,19 @@
|
||||||
|
\b;Exercice
|
||||||
|
Several \l;information exchange posts\u object\exchange; are standing along the way. When the bot is close enough to a post, it can read the instructions it contains. The \l;information exchange posts\u object\exchange; along the way contain the direction of the next post and the distance. And you do not know how many exchange posts you must get in touch with before arriving at your goal.
|
||||||
|
|
||||||
|
\b;General principle
|
||||||
|
Always repeat:
|
||||||
|
o Retrieve the direction from the \l;exchange post\u object\exchange;.
|
||||||
|
o Retrieve the distance from the \l;exchange post\u object\exchange;.
|
||||||
|
o If no information could be retrieved, stop the program.
|
||||||
|
o Execute the rotation.
|
||||||
|
o Move forward to the next post.
|
||||||
|
|
||||||
|
\b;Useful instructions
|
||||||
|
\c;\l;while\u cbot\while;\n; to repeat the instructions
|
||||||
|
\c;\l;receive\u cbot\receive;\n; to get the information from a post
|
||||||
|
\c;\l;move\u cbot\move;\n; to move the bot
|
||||||
|
\c;\l;turn\u cbot\turn;\n; to turn the bot
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,20 @@
|
||||||
|
\b;Exercise
|
||||||
|
You must follow the \l;target bot\u object\bottr; with the explosive device, but without touching it, otherwise it will blow up. Every time the target bot stops, you must be close to it (less than 10m). After you managed to stay close to the target bot at 10 successive stops, it will lead you to the finishing pad, and the exercise is over. At every stop, the target bot checks that you are there. If you are not there, you must start over again.
|
||||||
|
|
||||||
|
\b;General principle
|
||||||
|
Repeat forever:
|
||||||
|
o Look for the target bot.
|
||||||
|
o Calculate the distance to the bot.
|
||||||
|
o if the distance to the target bot is less than 5m, move backward.
|
||||||
|
o Otherwise, calculate the direction of the target bot, and move towards it.
|
||||||
|
|
||||||
|
\b;Useful instructions
|
||||||
|
\c;\l;radar\u cbot\radar;\n; to look for the bot (category \c;\l;TargetBot\u object\bottarg;\n;)
|
||||||
|
\c;\l;radar\u cbot\radar;\n; to detect obstacles
|
||||||
|
\c;\l;distance\u cbot\dist;\n; to calculate a distance
|
||||||
|
\c;\l;direction\u cbot\direct;\n; to calculate a direction
|
||||||
|
\c;\l;if\u cbot\if;\n; to test a condition
|
||||||
|
\c;\l;motor\u cbot\motor;\n; to set the motor speeds
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,11 @@
|
||||||
|
\b;Exercise
|
||||||
|
Destroy all four \l;targets\u object\bottarg; with a program using a \c;for\n; loop. You must move 10m to get from one target to another.
|
||||||
|
|
||||||
|
\b;Useful instructions
|
||||||
|
\c;\l;for\u cbot\for;\n; loop to repeat the instructions
|
||||||
|
\c;\l;move\u cbot\move;\n; to move the bot
|
||||||
|
\c;\l;turn\u cbot\turn;\n; to turn the bot
|
||||||
|
\c;\l;fire\u cbot\fire;\n; to fire the cannon
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,15 @@
|
||||||
|
\b;Exercise
|
||||||
|
Defend against all enemy attacks
|
||||||
|
|
||||||
|
\b;General idea
|
||||||
|
The range of your cannon is about 40m. The category of the enemies is \c;AlienAnt\n;. Turn towards the closest ant, even if it is still more than 40m away. But shoot only when it is closer than 40m, in order not to waste your energy.
|
||||||
|
|
||||||
|
\b;Useful instructions
|
||||||
|
\c;\l;radar\u cbot\radar;\n; to detect your enemies (category \c;\l;AlienAnt\u object\ant;\n;)
|
||||||
|
\c;\l;direction\u cbot\direct;\n; to calculate a direction
|
||||||
|
\c;\l;distance\u cbot\dist;\n; to calculate a distance
|
||||||
|
\c;\l;fire\u cbot\fire;\n; to fire your cannon
|
||||||
|
\c;\l;wait\u cbot\wait;\n; to wait
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,11 @@
|
||||||
|
\b;Exercise
|
||||||
|
Program the bot so that it will find its way without hitting the walls of the labyrinth. We suppose that you do not know the configuration of the labyrinth, but there are no bifurcations, and no dead-ends. The labyrinth is made of squares measuring 5m each.
|
||||||
|
|
||||||
|
\b;Useful instructions
|
||||||
|
\c;\l;radar\u cbot\radar;\n; to detect obstacles
|
||||||
|
\c;\l;if\u cbot\if;\n; to test a condition
|
||||||
|
\c;\l;move\u cbot\move;\n; to move the bot
|
||||||
|
\c;\l;turn\u cbot\turn;\n; to turn the bot
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,10 @@
|
||||||
|
\b;Exercise
|
||||||
|
Program the robot in such a way that it arrives on the finishing pad, after having passed by the three blue crosses.
|
||||||
|
The platforms and the crosses are all distant of 20m from each other.
|
||||||
|
|
||||||
|
\b;Useful instructions
|
||||||
|
\c;\l;move\u cbot\move;\n; to move the bot
|
||||||
|
\c;\l;turn\u cbot\turn;\n; to turn the bot
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,21 @@
|
||||||
|
\b;Exercice
|
||||||
|
\b;Exercise
|
||||||
|
The \l;bot\u object\bottr; must pass over all the \l;blue crosses\u object\waypoint; on the ground. The way that must be covered is made of two squares. The first one measures 15 meters, the second 25 meters.
|
||||||
|
|
||||||
|
\image tproc1a 8 8;
|
||||||
|
\b;General principle
|
||||||
|
In order to solve this problem, the most efficient solution consists in creating a \l;function\u cbot\function; that instructs the bot to move on a square shape of a certain size. The main program becomes then very simple:\c;
|
||||||
|
\c;
|
||||||
|
\s; extern void object::Function3( )
|
||||||
|
\s; {
|
||||||
|
\s; Square(15);
|
||||||
|
\s; Square(25);
|
||||||
|
\s; }
|
||||||
|
\n;
|
||||||
|
\b;Useful instructions
|
||||||
|
\c;\l;for\u cbot\for;\n; loop to repeat some instructions
|
||||||
|
\c;\l;move\u cbot\move;\n; to move the bot
|
||||||
|
\c;\l;turn\u cbot\turn;\n; to turn the bot
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,14 @@
|
||||||
|
\b;Exercise
|
||||||
|
Follow the way in form of a spiral. The bot must move 2 times 25m forward and turn, then move 2 times 20m forward and turn, and so on.
|
||||||
|
\image tproc2 8 8;
|
||||||
|
|
||||||
|
\b;Function
|
||||||
|
You will have noticed that the way is made of "L"-shaped parts that are fit one into another. The first one (dark blue) measures two times 25 meters. The second one (light blue) measures 5 meters less. Let us start with writing the \l;function\u cbot\function; that will move the bot on a "L"-shaped part whose length will be given as a parameter.
|
||||||
|
|
||||||
|
\b;Useful instructions
|
||||||
|
\c;\l;for\u cbot\for;\n; loop to repeat some instructions
|
||||||
|
\c;\l;move\u cbot\move;\n; to move the bot
|
||||||
|
\c;\l;turn\u cbot\turn;\n; to turn the bot
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,14 @@
|
||||||
|
\b;Exercise
|
||||||
|
In this exercise, a "crazy bot" places many \l;blue crosses\u object\waypoint; on the ground. Just try to find them all.
|
||||||
|
|
||||||
|
\b;Useful instructions
|
||||||
|
\c;\l;radar\u cbot\radar;\n; to detect the blue crosses (category \c;\l;WayPoint\u object\waypoint;\n;)
|
||||||
|
\c;\l;direction\u cbot\direct;\n; to calculate a direction
|
||||||
|
\c;\l;if\u cbot\if;\n; to test a condition
|
||||||
|
\c;\l;motor\u cbot\motor;\n; to set the motor speeds
|
||||||
|
|
||||||
|
\t;Remark
|
||||||
|
Do not wait too long, because the crazy bot gets down to work immediately. Fortunately, as long as you are in the program editor, the game will pause.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,35 @@
|
||||||
|
\b;Exercise
|
||||||
|
Convert some \l;titanium ore\u object\titanore; to \l;titanium cubes\u object\titan;, then drop 2 titanium cubes on the pads whose coordinates are:
|
||||||
|
\c;
|
||||||
|
x=10, y=-60
|
||||||
|
x=10, y=-65
|
||||||
|
\n;
|
||||||
|
\image derrick 8 8;
|
||||||
|
The \l;derrick\u object\derrick; extracts titanium ore from the subsoil; you just have to pick it up.
|
||||||
|
|
||||||
|
\image convert 8 8;
|
||||||
|
The \l;converter\u object\convert; converts titanium ore to titanium cubes. Just drop the titanium ore on the platform, move backward, and wait until it has been converted.
|
||||||
|
|
||||||
|
\b;General principle
|
||||||
|
Repeat two times :
|
||||||
|
o Wait until there is some titanium ore.
|
||||||
|
o Go to the titanium ore.
|
||||||
|
o Pick it up.
|
||||||
|
o Go to the converter.
|
||||||
|
o Drop the titanium ore.
|
||||||
|
o Move back 2.5 meters.
|
||||||
|
o Wait until there is a titanium cube.
|
||||||
|
o Pick up the titanium cube.
|
||||||
|
o Go to the platform.
|
||||||
|
o Drop the titanium cube.
|
||||||
|
|
||||||
|
\b;Useful instructions
|
||||||
|
\c;\l;for\u cbot\for;\n; to repeat some instructions
|
||||||
|
\c;\l;do - while\u cbot\do;\n; to repeat some instructions
|
||||||
|
\c;\l;radar\u cbot\radar;\n; to look for different objects
|
||||||
|
\c;\l;goto\u cbot\goto;\n; to move the bot
|
||||||
|
\c;\l;grab\u cbot\grab;\n; to grab an object
|
||||||
|
\c;\l;drop\u cbot\drop;\n; to drop an object
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,11 @@
|
||||||
|
\b;Exercise
|
||||||
|
Move the \l;titanium cube\u object\titan; on the finishing pad. You do not know the position of the titanium, but we can tell you the position of the finishing pad x=10 and y=-60.
|
||||||
|
|
||||||
|
\b;Useful instructions
|
||||||
|
\c;\l;radar\u cbot\radar;\n; to find the titanium cube (category \c;\l;Titanium\u object\titan;\n;)
|
||||||
|
\c;\l;goto\u cbot\goto;\n; to move the bot
|
||||||
|
\c;\l;grab\u cbot\grab;\n; to grab an object
|
||||||
|
\c;\l;drop\u cbot\drop;\n; to drop an object
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,26 @@
|
||||||
|
\b;Exercise
|
||||||
|
Instruct the bot to find all the \l;blue crosses\u object\waypoint; on the ground, but do not get too close to the \l;mines\u object\mine;. When the bot passes over a cross, it disappears. Here is the general principle:
|
||||||
|
|
||||||
|
Repeat forever:
|
||||||
|
o Look for a mine
|
||||||
|
o If a mine has been found, calculate the opposite direction
|
||||||
|
o Look for a cross
|
||||||
|
o If nothing has been found, stop the program
|
||||||
|
o Calculate the direction of the cross
|
||||||
|
o Calculate the mean value of the two directions
|
||||||
|
o Set the motor speeds in order to head towards the mean direction
|
||||||
|
|
||||||
|
\b;The instruction \c;radar\n;
|
||||||
|
In order to detect a mine with the \c;\l;radar\u cbot\radar;\n;, we recommend the following parameters:
|
||||||
|
\c;\s; radar(Mine, 0, 180, 0, 5);\n;
|
||||||
|
With the opening angle of 180 degrees, mines that are behind the bot will not be found. Mines that are at more than 5 meters are also ignored.
|
||||||
|
|
||||||
|
In order to find a blue cross, simply write:
|
||||||
|
\c;\s; radar(WayPoint);\n;
|
||||||
|
Blue crosses will be found everywhere.
|
||||||
|
|
||||||
|
In order to calculate a direction, use \c;\l;direction\u cbot\direct;\n;.
|
||||||
|
In order to set the motor speeds, use \c;\l;motor\u cbot\motor;\n;.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,7 @@
|
||||||
|
\b;Exercise
|
||||||
|
Instruct your \l;bot\u object\bottr; to find all the \l;blue crosses\u object\waypoint; on the ground, but do not get too close to the \l;mines\u object\mine;.
|
||||||
|
|
||||||
|
If a bot gets within less than 2m of the center of a mine (which is the position returned by the radar instruction), il will blow up. However, you must take into account the inertia of the bot. Probably a safety distance of 3 to 3.5m would be more appropriate.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
|
@ -0,0 +1,5 @@
|
||||||
|
\b;Objective
|
||||||
|
Here you can play around without any definite objective. You can do whatever you want, explore the region, build a base camp and several bots, run various research programs, kill the insects if you find some, etc.
|
||||||
|
|
||||||
|
\t;See also
|
||||||
|
\l;Controls\u command;.
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue