Category:Console Command: Difference between revisions

From OpenKore Wiki
Jump to navigation Jump to search
mNo edit summary
(registering commands)
Line 4: Line 4:
* manually typing in the console
* manually typing in the console
* calling via [[doCommand]], [[macro]]'s '''do''', cmdOnLogin and other plugins
* calling via [[doCommand]], [[macro]]'s '''do''', cmdOnLogin and other plugins
* calling via <code>Commands::run("<console command with arguments>")</code> - that can br used inside Kore, in plugins and in [[eval]]
* 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.
Regardless of way used, the syntax and command set is the same.


Line 10: Line 10:


Aliases (shortcuts) for already existing commands can be defined with [[alias]].
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) });

Revision as of 22:37, 4 September 2010

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. 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) });