Colobot Wiki

Instruction public (for specialists)[]

This instruction has two distinct purposes:

  1. Make a function available to other bots.
  2. Make a class member accessible from outside the class definition.

Instruction public for functions[]

If you put public before a function definition, you can make the function available to programs in other bots in the same mission.

For example in the first bot we would have:

public void object::Segment(float dist, float angle)

And in another bot we would have:

extern void object::Square( )
	for ( int i=0 ; i<4 ; i++ )
		Segment(10, 90);

If you have declared a function public, you cannot define a function with the same name and arguments in another bot of the same mission.

If a bot containing a public function is destroyed, the other bots that make use of this function will be stopped with an error.

Instruction public for classes[]

Public is also an access modifier for class members, which is the default one. Public members can be accessed from outside of the class definition.

public class MyClass
	int    b;                // public by default
	public int a;            // also public
	private point position;  // private
void Test()
	MyClass item;
	item.a = item.b = 12;      // ok
	message( item.position );  // this is an error

See also[]