Colobot Wiki
Advertisement

Syntax[]

object search(int category);
object search(int category, point center);
object search(int category, float x, float y );

Description[]

Search functions similarly to radar, but can be centered on locations other than the current bot. When no location argument is given, the search is centered on the executing bot, so:

search( PowerCell );

is equivalent to:

radar( PowerCell );

Return Value[]

Returns a reference to the object of the specified category nearest to the specified location, or null if no such object exists.

Example[]

object conv, cube;

conv = radar( Converter );
if( conv != null )
{
    cube = search(Titanium, conv.position.x, conv.position.y);
    if( cube == null or distance( cube.position, conv.position ) > 2 )
    {
        //There is no Titanium in the converter, go find some
        loadTitanium();
    }
}


The above example checks for Titanium at the nearest Converter and calls another function "loadTitanium()" if the Converter is empty (n.b. To be useful, the function should also check for TitaniumOre).

See also[]

CBOT Language and radar

Advertisement