FANDOM


The CBOT language is very close in structure and syntax to C++ and Java. It has been adapted for the specific
Big03e

The CoLoBoT code editor window.

purposes of COLOBOT, and for an efficient pedagogical approach.

This language is made up of instructions (see below), blocks, functions, classes, variables, arrays, expressions and conditions.

InstructionsEdit

In the program editor, an instruction in the CBOT language is always displayed on an orange background. If an instruction doesn't have an orange background, this means that it has been misspelled. Instruction names are always written in lower case.

Types in the CBOT languageEdit

The type of a variable appears with a green background.

int
float
bool
string
point
object
void

ConstantsEdit

Constants, like categories, are displayed with a red background.

Instructions in the CBOT languageEdit

extern Indicate the main function
if Choice structure
else if Consequence of if and else syntax, alternative if
else Alternative choice structure
for Loop structure
while Control structure
do Control structure
break Exit from a loop
continue Continues the loop
return Exit from a function
sizeof Size of an array

do ... whileEdit

You can have do ... while loops.

   do {
       // things
   } while (stuff());

Operators in the CBOT languageEdit

+ addition
- subtraction
* multiplication
/ division
 % modulus (only for int type)
or Boolean or with short-circuiting
and Boolean and with short-circuiting
not Boolean not
== Equal
!= Not equal
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
? : The ternary operator .

Specific instructions for botsEdit

radar Object detection
search Object detection
direction Calculates a rotation angle
distance Calculates a distance
distance2d Calculates a distance
wait Waits
move Moves forward or backward
turn Turns
goto Goes to a given position
motor Direct motor control
jet Direct jet engine control
message Displays a message
retobject Returns an object from array
errmode Error treatment control
abstime Returns the absolute time
ipf Sets execution speed
pendown Begin leaving a trail behind the bot
penup Stop leaving a trail behind the bot
penwidth Change the trail's width
pencolor Change the trail's height

Instructions about topologyEdit

space Calculates a free space
topo Returns the altitude of a point
flatground Returns radius of a flat area

Instructions specific to some botsEdit

grab Picks up an object
drop Puts down an object
sniff Sounds the subsoil
thump Overturns alien insects
recycle Recycles a derelict bot
shield Extends or withdraws the shield
fire Fires the cannon
aim Vertical angle of the cannon

Specific instructions for exchange postsEdit

receive Receives an information
send Sends a new information
testinfo Tests if an information exists
deleteinfo Deletes an existing information

Specific instructions for classesEdit

class Class declararion
public Declares a public function
private Declares a private class member
static Declares a static class member
synchronized Prevents simultaneous execution
new Creates a new instance
this Reference to the current instance

Specific instructions for stringsEdit

strlen Gets string length
strleft Extracts left part
strright Extracts right part
strmid Extracts center part
strfind Finds a substring
strval Converts string to number
strupper Converts to upper case
strlower Converts to lower case

Mathematical FunctionsEdit

abs(value) absolute value of an argument
sin(angle) sine
cos(angle) cosine
tan(angle) tangent
asin(value) arcsine
acos(value) arccosine
atan(value) arctangent
sqrt(value) square root
pow(x, y) x to the power y (x^y)
rand() random number in range between 0 and 1

Specific instructions for filesEdit

open Opens a file
close Closes a file
writeln Writes line to a file
readln Reads line from a file
eof Tests if end of file
deletefile Deletes a file

Tricks and notesEdit

See what happens when you try theseEdit

Some functions to mess around with and see what they do (if they even work):

   produce - создать объект
   cmdline
   ismovie
   repeat
   drive

Object PropertiesEdit

All objects have at least some of the following properties:

  • object.category - this is probably so you can do stuff like target.category == AlienAnt
  • object.position
  • object.orientation - presumably yaw, all angles are in degrees.
  • object.pitch
  • object.roll
  • object.energyLevel - the amount of energy left in the battery, from 1 to 0. Float. May work only on batteries. For robots try robot.energyCell.energyLevel
  • object.shieldLevel
  • object.temperature - temperature of the jet engine. 0 is cool, 1 is overheated.
  • object.altitude - height above the ground. Same as (object.position.z - topo(object.position)) .
  • object.lifeTime - time since creation of the object. Float. In seconds.
  • object.energyCell - the object in a robot's battery holder, or none if there's nothing there.
  • object.load - the entity that the object is carrying, if it's a grabber.

Robot AttributesEdit

You can get the thing a grabber is holding with this.load. It'll probably be null if there's nothing being held.

You can get the entity in the battery slot with this.energyCell.

Context AssignmentEdit

It's possible to have a variable assignment inside of another context, like in C. For example:

   extern void object::Main() {
       object target;
       
       while ((target = radar()) != null) {
           // do things
       }
   }

Note the second parentheses. This example is the equivalent of running:

   extern void object::Main() {
       object target = radar();
       
       while (target != null) {
           // do things
           target = radar();
       }
   }

LimitationsEdit

You can't use array literals. This won't work:

object enemy = radar({AlienAnt, AlienSpider});

Instead, you need to do:

object[] enemyClasses = {AlienAnt, AlienSpider};
object enemy = radar(enemyClasses);

There's no polymorphism in CBOT, so functions need to be redefined for every type that they might need to work on.

Dying Enemies Edit

There's no way to tell if an enemy is in the process of dying by looking at its properties, but a dead enemy's lifeTime will no longer go up.

See alsoEdit

Types and categories.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.