01-20-2015, 11:03 PM
Short description:
There's a mysterious try...catch block statement in CBot that allows you to interrupt normally non-interruptible instructions, like move() and goto().
Long description:
The statement looks similar to try...catch blocks found in many high-level programming languages like C++ and Java. However, in catch() you can put a condition that will be checked every in-game tick. If this condition becomes true, code in try block will be interrupted and control will be returned to the catch block. This allows you to interrupt your program if something extraordinary happens. For example, you can check if an ant is nearby and return back to base to escape the danger.
There is no information about it in CBot manual. It was found in one of the documents EPSITEC gave us together with source code of Colobot.
There's a mysterious try...catch block statement in CBot that allows you to interrupt normally non-interruptible instructions, like move() and goto().
Long description:
The statement looks similar to try...catch blocks found in many high-level programming languages like C++ and Java. However, in catch() you can put a condition that will be checked every in-game tick. If this condition becomes true, code in try block will be interrupted and control will be returned to the catch block. This allows you to interrupt your program if something extraordinary happens. For example, you can check if an ant is nearby and return back to base to escape the danger.
Code:
try
{
object item = radar(TitaniumOre);
goto(item.position);
grab();
// take ore to converter
}
catch(radar(AlienAnt, 0, 360, 0, 40) != null)
{
message("Ant is attacking me! Returning to base.");
object item = radar(SpaceShip);
goto(item.position);
}
There is no information about it in CBot manual. It was found in one of the documents EPSITEC gave us together with source code of Colobot.
"After three days without programming, life becomes meaningless."
~The Tao of Programming
~The Tao of Programming