View Full Version : Slash handlers in table extension

June 30th, 2016, 09:29
A proof of concept for improving the utility of the slash command. By replacing the onSlashCommand function with one that draws from a table, ruleset and extension creators can easily add their new commands to the list.

I'd be happy if this made its way directly into the CoreRPG ruleset, but this can also be implemented in individual rulesets.

June 30th, 2016, 12:59
I've moved this to its own thread so that questions can be asked etc..

Interesting concept. Could you please provide info on how it works, what benefits it has over the current slash handlers, etc.. Thanks.

June 30th, 2016, 14:42
1. It overrides the ChatManager.onSlashCommand() function.
2. It creates a hashtable, GameSystem.slashcommands, which stores info on all of the commands available.
3. It demonstrates how to add new items to GameSystem.slashcommands from a ruleset or extension, and how to add a basic new command.

In the CoreRPG (original) version of onSlashCommand(), the list of slash-commands that get shown when a user types '/?' is hardcoded, and cannot be easily added to. There's a list of host-only commands, and a list that are available to all users.

In ImprovedSlashCommand.ext, the list is moved out of the function into a hashtable. I chose a hashtable instead of an array because it allows developers to look up and override an individual key. If, for instance, a ruleset or extension registers '/table' to roll on a table, and '/roll' to roll dice the same way '/die' does, they could replace the '/?' listing for '/roll' simply by using

GameSystem.slashcommands["roll"] = {GMonly=false, message="/roll [NdN+N] <message>"}

(That's my preference, since /roll intuitively makes more sense and has been the convention since IRC was a thing.)

(Edit: /roll currently does not appear in the list, which is part of the reason I chose it; it should be added at some point, so I took the opportunity to slide that in here. It's so very minor, but since I've already broached the general topic...)

GMonly sets whether the command is only available to the GM, or should be shown to the players. message is the text content you wish to add to what is output when a user types /?

June 30th, 2016, 15:27
This also would pave the way for /? <command> functionality. A
verbose = "longer, more in-depth explanation"
key could be added to an entry in GameSystem.slashcommands. Then the slash interpreter would look for a match from the table, preferring the verbose entry but falling back on the message entry, and if the key is not present, displaying the normal list of commands.