| 1 | = ConsoleCommand = |
| 2 | [[TracNav(TracNav/TOC_Development)]] |
| 3 | |
| 4 | == Description == |
| 5 | A !ConsoleCommand is a function which can be called by the [wiki:Shell]. !ConsoleCommand inherits from [wiki:Executor] and adds some additional features used to [wiki:KeyBinder bind commands to keys] and to allow easy use in the Shell ([wiki:ArgumentCompleter like argument completion]). |
| 6 | |
| 7 | At the moment, a !ConsoleCommand must call a '''static''' function. The command is of static nature too and exists for the whole time. But this will change in the future. |
| 8 | |
| 9 | A !ConsoleCommand can also be called directly from the code by using [wiki:CommandExecutor]. If you want to execute the same command over and over, see [wiki:CommandEvaluation] for more performance. |
| 10 | |
| 11 | == Usage == |
| 12 | === Creation === |
| 13 | Creating a !ConsoleCommand is usually really easy. Just write the following lines: |
| 14 | |
| 15 | *.cc file: |
| 16 | {{{ |
| 17 | #include "core/ConsoleCommand.h" |
| 18 | |
| 19 | SetConsoleCommand(ClassName, functionname, true); |
| 20 | }}} |
| 21 | Note: The last argument (true) means: create a shortcut for this command. |
| 22 | |
| 23 | *.h file: |
| 24 | {{{ |
| 25 | class ClassName |
| 26 | { |
| 27 | public: |
| 28 | static returntype functionname(param1, param2, ...); |
| 29 | }; |
| 30 | }}} |
| 31 | |
| 32 | === Call === |
| 33 | Now you can call the function by typing the ''functionname'' into the [wiki:Shell]: |
| 34 | {{{ |
| 35 | > functionname arg1 arg2 ... |
| 36 | or |
| 37 | > ClassName functionname arg1 arg2 ... |
| 38 | }}} |
| 39 | |
| 40 | Note: The first variant works only if you enable the shortcut (''true'' in SetConsoleCommand). |
| 41 | |
| 42 | It's also possible to call the command directly from the code by using [wiki:CommandExecutor]: |
| 43 | {{{ |
| 44 | CommandExecutor::execute("functionname arg1 arg2 ..."); |
| 45 | or |
| 46 | CommandExecutor::execute("ClassName functionname arg1 arg2 ..."); |
| 47 | }}} |
| 48 | |
| 49 | === Attributes === |
| 50 | There are several attributes you can set, some of them are inherited from [wiki:Executor], some are new. |
| 51 | |
| 52 | '''Inherited''': |
| 53 | * '''description('''''description''''')''': Sets the description of the Executor (what the function does) |
| 54 | * '''descriptionParam('''''param number (0-4)''''', '''''description''''')''': Sets the description of an argument (what the argument does) |
| 55 | * '''descriptionReturnvalue('''''description''''')''': Sets the description of the return value (what the return value does) |
| 56 | |
| 57 | * '''defaultValues('''''value1''''', '''...''')''': Sets default values |
| 58 | * '''defaultValue('''''param number (0-4)''''', '''''value''''')''': Sets the default value for a given parameter |
| 59 | |
| 60 | '''New''': |
| 61 | * '''accessLevel('''''level''''')''': Sets the access level (see [wiki:ConsoleCommand#AccessLevels the chapter below]) |
| 62 | * '''argumentCompleter('''''param number (0-4)''''', '''''completer''''')''': Sets the [wiki:ArgumentCompleter] for a given parameter (see [wiki:ConsoleCommand#ArgumentCompletion the chapter below]) |
| 63 | |
| 64 | * '''keybindMode('''''mode''''')''': |
| 65 | * '''axisParamIndex('''''index''''')''': |
| 66 | * '''isAxisRelative('''''bool''''')''': |
| 67 | |
| 68 | === Chained attributes === |
| 69 | You can specify all attributes from above in one single chained call, for example: |
| 70 | {{{ |
| 71 | SetConsoleCommand(ClassName, functionname, true).description("Does something nice").defaultVal |
| 72 | ues(10, "test", true, 1.234).argumentCompleter(0, autocompletion::completerfunction()).isA |
| 73 | xisRelative(true); |
| 74 | }}} |
| 75 | Note: The attributes can be specified in any order. |
| 76 | |
| 77 | == Access Levels == |
| 78 | |
| 79 | == Argument Completion == |