The synchronized keyword may be added to a function declaration to prevent multiple bots from executing the function at the same time. Obviously, it is only useful when declaring a public function such as a class member function.


public class T3C
    int x;

    synchronized void setx( int arg )
        x = arg;

    synchronized int getx()
        return x;

Unlike a traditional mutex structure, all synchronized functions in a class implicitly share a single mutex, hence while one bot is running setx() in the example above, any other attempts to run setx() or getx() will block until the running setx() returns.


In Colobot 1.8 apparently anything that causes script execution on a particular bot to halt while it is executing a synchronized function will not reliably release the mutex. Hence all subsequent attempts to call that synchronized function (or any other synchronized function in that class) will block.

Events that can trigger this bug include the user pressing the "stop" button, the bot being destroyed, or execution halting due to an error. One possible workaround is to save, exit and re-load the game.

See also.Edit

CBOT Language