Category:Console Command: Difference between revisions

From OpenKore Wiki
Jump to navigation Jump to search
m (create page for category:Console Command)
 
No edit summary
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Console Commands
Console commands are used to control and inspect Kore while it's running.
 
There are many ways how console commands can be invoked:
* manually typing in the console
* calling via [[doCommand]], [[macro plugin|macro]]'s '''do''', cmdOnLogin and other plugins
* calling via <code>Commands::run("<console command with arguments>")</code> - that can be used inside Kore, in plugins and in [[eval]]
Regardless of way used, the syntax and command set is the same.
 
Some console commands are equivalent to the manual actions you can do in the original Ragnarok Online Client (e.g. [[Client Commands|client commands]], chatting, dealing, party and guild management, etc); some are used for controlling more high-level Kore's AI; some are used for inspect your character, environment, AI etc.
 
Aliases (shortcuts) for already existing commands can be defined with [[alias]].
 
== Adding Custom Commands ==
 
Plugins can add new commands.
 
Registering of new commands (can be used outside of subs in a plugin):
my $commands_handle = Commands::register(
['command_name', 'command description', <code_reference>],
...
)
Where:
* $commands_handle is a scalar variable to hold obscure content used for unregistering
* command_name is a command
* command description is a description for user
* code_reference is a Perl coderef for a command handler, can be for example a reference to the existing sub <code>\&sub_name</code> or lambda <code>sub { ... }</code>
 
Command handler is called with two arguments: command name and the rest of the string (command arguments).
 
Unregistering of commands (should be used in plugin's reload/unload handlers):
Commands::unregister($commands_handle)
 
=== Example ===
 
# very simple plugin which adds '''echo''' command which just prints its arguments to the console
package echo;
use strict;
my $commands = Commands::register(['echo', 'print to the console', sub { Log::message "$_[1]\n" }]);
Plugins::register("echo", "echo command", sub { Commands::unregister($commands) });

Latest revision as of 17:56, 11 December 2016

Console commands are used to control and inspect Kore while it's running.

There are many ways how console commands can be invoked:

  • manually typing in the console
  • calling via doCommand, macro's do, cmdOnLogin and other plugins
  • calling via Commands::run("<console command with arguments>") - that can be used inside Kore, in plugins and in eval

Regardless of way used, the syntax and command set is the same.

Some console commands are equivalent to the manual actions you can do in the original Ragnarok Online Client (e.g. client commands, chatting, dealing, party and guild management, etc); some are used for controlling more high-level Kore's AI; some are used for inspect your character, environment, AI etc.

Aliases (shortcuts) for already existing commands can be defined with alias.

Adding Custom Commands

Plugins can add new commands.

Registering of new commands (can be used outside of subs in a plugin):

my $commands_handle = Commands::register(
	['command_name', 'command description', <code_reference>],
	...
)

Where:

  • $commands_handle is a scalar variable to hold obscure content used for unregistering
  • command_name is a command
  • command description is a description for user
  • code_reference is a Perl coderef for a command handler, can be for example a reference to the existing sub \&sub_name or lambda sub { ... }

Command handler is called with two arguments: command name and the rest of the string (command arguments).

Unregistering of commands (should be used in plugin's reload/unload handlers):

Commands::unregister($commands_handle)

Example

# very simple plugin which adds echo command which just prints its arguments to the console
package echo;
use strict;
my $commands = Commands::register(['echo', 'print to the console', sub { Log::message "$_[1]\n" }]);
Plugins::register("echo", "echo command", sub { Commands::unregister($commands) });