2013-03-29 09:01:03 +00:00
\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;.
2015-08-31 15:36:20 +00:00
\l;o\u cheats; \c;\token;Instructions\norm;\n;
2015-08-18 19:14:41 +00:00
In the program editor, an instruction in the CBOT language is always displayed like that: \token;instruction\norm;. If an instruction is not highlighted, this means that it has been misspelled. Instruction names are always written in lower case.
2013-03-29 09:01:03 +00:00
o \c;\type;Type\norm;\n;
2015-08-18 19:14:41 +00:00
The \l;type\u cbot\type; of a variable appears like that: \type;type\norm;.
2013-03-29 09:01:03 +00:00
o \c;\const;Constants\norm;\n;
2015-08-18 19:14:41 +00:00
Constants like \l;categories\u cbot\category; are displayed like that: \const;constant\norm;.
2013-03-29 09:01:03 +00:00
\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
2015-07-28 15:20:09 +00:00
\c;\l;switch\u cbot\switch; \n;Multiple choice structure
\c;\l;case\u cbot\switch; \n;One choice
\c;\l;default\u cbot\switch; \n;Default choice
2013-03-29 09:01:03 +00:00
\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:
2015-08-13 09:36:04 +00:00
\c;\l;detect\u cbot\detect; \n;Simple object detection
\c;\l;radar\u cbot\radar; \n;Advanced object detection
2016-03-06 12:48:50 +00:00
\c;\l;radarall\u cbot\radarall; \n;Advanced multiple objects detection
2015-07-27 13:23:49 +00:00
\c;\l;search\u cbot\search; \n;Object detection from a specific point
2013-03-29 09:01:03 +00:00
\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
2015-07-26 19:36:09 +00:00
\c;\l;pendown\u cbot\pendown; \n;Starts drawing
\c;\l;penup\u cbot\penup; \n;Stops drawing
\c;\l;pencolor\u cbot\pencolor; \n;Changes the pen color
\c;\l;penwidth\u cbot\penwidth; \n;Changes the pen width
2015-07-27 11:22:56 +00:00
\c;\l;canresearch\u cbot\canresearch; \n;Checks if a technology can be researched
\c;\l;researched\u cbot\researched; \n;Checks if a technology is researched
2013-03-29 09:01:03 +00:00
\t;Instructions about topology:
\c;\l;space\u cbot\space; \n;Calculates a free space
2015-07-27 11:40:50 +00:00
\c;\l;flatspace\u cbot\flatspace; \n;Calculates a free, flat space
2013-03-29 09:01:03 +00:00
\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
2015-07-23 14:10:35 +00:00
\c;\l;aim\u cbot\aim; \n;Rotates the cannon
2015-07-23 13:25:15 +00:00
\c;\l;build\u cbot\build; \n;Builds a building
2015-07-23 18:55:07 +00:00
\c;\l;canbuild\u cbot\canbuild; \n;Checks if a building can be built
\c;\l;buildingenabled\u cbot\buildingenabled; \n;Checks if a building can be built in the level
2013-03-29 09:01:03 +00:00
2015-07-26 14:32:13 +00:00
\t;Instructions specific for some \l;objects\u cbot\object;:
\c;\l;factory\u cbot\factory; \n;Starts construction of a bot
\c;\l;research\u cbot\research; \n;Starts a research
\c;\l;takeoff\u cbot\takeoff; \n;Takes off a spaceship
\c;\l;busy\u cbot\busy; \n;Checks if object is busy
2013-03-29 09:01:03 +00:00
\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
2016-09-10 14:09:04 +00:00
\c;\l;public\u cbot\public; \n;Declares a public class member
2013-03-29 09:01:03 +00:00
\c;\l;private\u cbot\private; \n;Declares a private class member
2016-09-10 14:09:04 +00:00
\c;\l;protected\u cbot\protected; \n;Declares a protected class member
2013-03-29 09:01:03 +00:00
\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
2016-09-10 15:48:46 +00:00
\c;\l;extends\u cbot\extends; \n;Extends a class
\c;\l;super\u cbot\super; \n;Grants access to the parent class
2013-03-29 09:01:03 +00:00
\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
2015-07-23 15:33:37 +00:00
\t;Mathematical functions:
\c;\l;rand\u cbot\rand; \n;Returns a random value
\c;\l;pow\u cbot\pow; \n;Returns a power
\c;\l;sqrt\u cbot\sqrt; \n;Returns a square root
2015-07-24 10:14:39 +00:00
\c;\l;floor\u cbot\floor; \n;Returns the largest previous integer
\c;\l;ceil\u cbot\ceil; \n;Returns the smallest following integer
\c;\l;round\u cbot\round; \n;Returns a rounded number
\c;\l;trunc\u cbot\trunc; \n;Returns a truncated number
2015-07-23 15:33:37 +00:00
\c;\l;sin\u cbot\sin; \n;Returns a sine
\c;\l;cos\u cbot\cos; \n;Returns a cosine
\c;\l;tan\u cbot\tan; \n;Returns a tangent
\c;\l;asin\u cbot\asin; \n;Returns an arcus sine
\c;\l;acos\u cbot\acos; \n;Returns an arcus cosine
\c;\l;atan\u cbot\atan; \n;Returns an arcus tangent
2015-07-24 10:14:39 +00:00
\c;\l;atan2\u cbot\atan2; \n;Returns an arcus tangent, has two arguments
2015-07-23 15:33:37 +00:00
2013-03-29 09:01:03 +00:00
\t;See also
\l;Types\u cbot\type; and \l;categories\u cbot\category;.