Talk:Main Page

From NeoAxis Engine Wiki

Jump to: navigation, search

To open a game console in game you have to hit tilde key "~".


You can set different commands in the console (as in many games). To get list of available commands you have to enter command "commands" without commas.

With help of class Engine.EngineConsole you could simply withdraw text in console:

Code:

    EngineConsole.Instance.Print( "Hello Console!" );

Even color:

Code:

    EngineConsole.Instance.Print( "Hello Console!", new ColorValue( 1.0f, 0.0f, 0.0f ) );

You can also add your command for the console:

EngineConsole.Instance.AddCommand( "my_command", my_command );

"my_command" - name of command (first argument) my_command – name of processor function (second argument)

To process command we need a function which returns nothing and takes 1 string argument: void my_command( string arguments ) { }

But if we want to send our command together with one or several arguments! We need to pull them from “arguments”. If one argument: void my_command( string arguments ) {

 		 int arg;
 		 if( !int.TryParse( arguments, out arg ) )
  		{
     			return; //Error – wrong argument
  		}
 		//Do something with our argument...

}

And if several arguments: void my_command( string arguments ) {

  		char[] splitter = new char[ 1 ] { ' ' };
  		string[] buf = arguments.Split( splitter );
 		 int arg1, arg2;
  		if( !int.TryParse( buf[ 0 ], out arg1 ) || !int.TryParse( buf[ 1 ], out arg2 ) )
  		{
    			 return; //Error – wrong arguments
  		}
  		//Do something with our arguments...

} splitter - symbol that separates arguments (in this example gap) buf - array of strings, where each row - our argument (as in the case of one argument) I gave an example with 2 arguments, but arguments can be more!

Now our command can be used in game, and can be called programmed: EngineConsole.Instance.ExecuteString( "my_command" );

Here, I described the most essential functions for the console

Personal tools