Colobot Wiki


object retobject(int index)


The Colobot game engine maintains a global array containing a reference to every object in the current game. The retobject() function returns the object from the a specified index.

i.e. if you had access to the array then:

object foo = retobject(14)

would be equivalent to:

object foo = globalobjects[14];

Return Value:[]

The object stored at the specified index or null if no object exists at that index.


The following function returns an array of points containing the locations of all items of the specified category in the current game:

point[] object::findAll( int findcat )
  int count = 0;
  object item;
  point found[] = null;
  for( int n = 0; (item = retobject(n)) != null; n++ )
    if( item.category == findcat and item.position.x != nan )
      found[count++] = item.position;
  return found;

This function iterates across all object in the current game and stores the current location of any objects of the category given by the argument. So


Would return all power cells sitting around on the ground in the current game. The test for "item.position.x != nan" is used to exclude items that are installed inside other items. If that condition were remove from the if statment then the above example would return a point for every PowerCell in the game, including those installed in bots and buildings (although the points for those power cells would have x, y and z values of nan).

See also.[]

CBOT Language