Fandom

Colobot Wiki

Retobject

67pages on
this wiki
Add New Page
Comments0 Share

Syntax:Edit

object retobject(int index)

Description:Edit

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:Edit

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

Example:Edit

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 )
{
  ipf(1000);
  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

findall(PowerCell);

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.Edit

CBOT Language

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.