ChatCmdBuilder: Add notes to be less misleading, also document luapatterns
This commit is contained in:
parent
a177c74f6d
commit
138daddb8b
@ -49,7 +49,7 @@
|
|||||||
num: 10
|
num: 10
|
||||||
link: chapters/chat.html
|
link: chapters/chat.html
|
||||||
|
|
||||||
- title: Complex Chat Commands
|
- title: Chat Command Builder
|
||||||
num: 11
|
num: 11
|
||||||
link: chapters/chat_complex.html
|
link: chapters/chat_complex.html
|
||||||
|
|
||||||
|
@ -106,14 +106,42 @@ to show a formspec, and `/inbox text` to send information to chat.
|
|||||||
|
|
||||||
It is often required to make complex chat commands, such as:
|
It is often required to make complex chat commands, such as:
|
||||||
|
|
||||||
* /msg <name> <message>
|
* `/msg <to> <message>`
|
||||||
* /team join <teamname>
|
* `/team join <teamname>`
|
||||||
* /team leave <teamname>
|
* `/team leave <teamname>`
|
||||||
* /team list
|
* `/team list`
|
||||||
|
|
||||||
Many mods implement this using Lua patterns; however, a much easier
|
This is usually done using [Lua patterns](https://www.lua.org/pil/20.2.html).
|
||||||
approach is to use a mod library. See rubenwardy's
|
Patterns are a way of extracting stuff from text using rules.
|
||||||
[Complex Chat Commands](chat_complex.html).
|
|
||||||
|
{% highlight lua %}
|
||||||
|
local to, msg = string.match(param, "^([%a%d_-]+) (*+)$")
|
||||||
|
{% endhighlight %}
|
||||||
|
|
||||||
|
The above implements `/msg <to> <message>`. Lets go through left to right:
|
||||||
|
|
||||||
|
* `^` means match the start of the string.
|
||||||
|
* `()` is a matching group - anything that matches stuff in here will be
|
||||||
|
returned from string.match.
|
||||||
|
* `[]` means accept characters in this list.
|
||||||
|
* `%a` means accept any letter and `%d` means any digit.
|
||||||
|
* `[%d%a_-]` means accept any letter or digit or `_` or `-`.
|
||||||
|
* `+` means match the last thing one or more times.
|
||||||
|
* `*` means match any character in this context.
|
||||||
|
* `$` means match the end of the string.
|
||||||
|
|
||||||
|
Put simply, this matches the name (a word with only letters/numbers/-/_),
|
||||||
|
then a space, then the message (one of more of any character). The name and
|
||||||
|
message are returned, as they're surrounded in parentheses.
|
||||||
|
|
||||||
|
That's how most mods implement complex chat commands. A better guide to Lua
|
||||||
|
Patterns would probably be the
|
||||||
|
[lua-users.org tutorial](http://lua-users.org/wiki/PatternsTutorial)
|
||||||
|
or the [PIL documentation](https://www.lua.org/pil/20.2.html).
|
||||||
|
|
||||||
|
There is also a library written by the author of this book which can be used
|
||||||
|
to make complex chat commands without Patterns called
|
||||||
|
[ChatCmdBuilder](chat_complex.html).
|
||||||
|
|
||||||
|
|
||||||
## Intercepting Messages
|
## Intercepting Messages
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
---
|
---
|
||||||
title: Complex Chat Commands
|
title: Chat Command Builder
|
||||||
layout: default
|
layout: default
|
||||||
root: ../../
|
root: ../../
|
||||||
---
|
---
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
|
|
||||||
This chapter will show you how to make complex chat commands, such as
|
This chapter will show you how to make complex chat commands with ChatCmdBuilder,
|
||||||
`/msg <name> <message>`, `/team join <teamname>` or `/team leave <teamname>`.
|
such as `/msg <name> <message>`, `/team join <teamname>` or `/team leave <teamname>`.
|
||||||
|
|
||||||
|
Note that ChatCmdBuilder is a library created by the author of this book, and most
|
||||||
|
modders tend to use the method outlined in the
|
||||||
|
[chat commnds](chat.html#complex-subcommands) chapter.
|
||||||
|
|
||||||
* Why ChatCmdBuilder?
|
* Why ChatCmdBuilder?
|
||||||
* Routes.
|
* Routes.
|
||||||
@ -100,6 +104,9 @@ end)
|
|||||||
|
|
||||||
## Installing ChatCmdBuilder
|
## Installing ChatCmdBuilder
|
||||||
|
|
||||||
|
The source code can be found and downloaded on
|
||||||
|
[Github](https://github.com/rubenwardy/ChatCmdBuilder/).
|
||||||
|
|
||||||
There are two ways to install:
|
There are two ways to install:
|
||||||
|
|
||||||
1. Install ChatCmdBuilder as a mod and depend on it.
|
1. Install ChatCmdBuilder as a mod and depend on it.
|
||||||
|
Loading…
Reference in New Issue
Block a user