Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Parse ¶
Parse initiates processing of the input string for the specified Thing. The input string is expected to be input from a player. The actual command processed will be returned. For example GET or DROP.
Parse runs with state.scripting set to false, disallowing scripting specific commands from being executed by players directly.
When sync handles a command the command may determine it needs to hold additional locks. In this case sync will return false and should be called again. This repeats until the list of locks is complete, the command processed and sync returns true.
Types ¶
type Result ¶ added in v0.0.13
Result is the result of a match. If the match is successful then Thing will be the matched Thing and Unknown and NotEnough will both be empty strings. If the match fails Thing will be nil. If the match fails due to unknown words then Unknown will be set to the unknown words. If the match fails because there are not enough matching Thing to satisfy a limit then NotEnough will be set to the words matched.
func Match ¶ added in v0.0.13
Match is shorthand for MatchLimit with a limit of 1.
func MatchAll ¶ added in v0.0.13
MatchAll is shorthand for MatchLimit with a limit of -1. It always consumes all words and returns no unused words.
func MatchLimit ¶ added in v0.0.13
func MatchLimit(wordList []string, limit int, inv ...[]has.Thing) (matches []Result, words []string)
MatchLimit tries to find Things in the given Inventory by matching aliases and qualifiers in the given word list. The limit is the number of groups of words to match. A group of words consisting of an alias plus zero or more qualifiers. A limit of -1 will consume all words in the list.
Assume the following items, aliases and qualifiers in square brackets and qualifiers have a leading '+' symbol:
a small green ball [+SMALL +GREEN BALL] a small red ball [+SMALL +RED BALL] a large green ball [+LARGE +GREEN BALL] a large red ball [+LARGE +RED BALL]
All matching processes the word list from right to left. This is because a group of words identifying one or more items always ends with an alias and can be preceded by one or more qualifiers. By default only the first item matching a word group will be returned.
With a word list of 'RED BALL GREEN BALL' a limit of 1 would consume two words 'GREEN BALL' and return one Thing matched: a small green ball. In this case the alias 'BALL' would match, followed by the qualifier 'GREEN'. As 'BALL' preceding 'GREEN' is not a qualifier matching fails and we have 'GREEN BALL' as the first matching group of words.
With a word list of 'RED BALL GREEN BALL' a limit of 2 (or -1) would consume all of the words and return two Thing matched: a small green ball, a small red ball. Note that the limit of 2 if the number of word groups, in this case 'RED BALL' and 'GREEN BALL' not the number of items to return.
Within a matching group of words the first qualifier may be special. The special qualifiers are:
ALL - include all items matching the current group n - include up to n items matching the current group nth - include only the nth item (postfix may be ST, ND, RD or TH) n-N - include only matching items n to N for the current group
With a word list of 'ALL GREEN BALL' all items matching the alias of 'BALL' with a qualifier of 'GREEN' will be returned. In this case: a small green ball, a large green ball.
With a word list of '2 BALL' the first 2 items matching the alias of 'BALL' will be returned. In this case: a small green ball, a small red ball.
With a word list of '2ND RED BALL' only the second item matching the alias of 'BALL' with a qualifier of 'RED' will be returned. In this case: a large red ball.
With a word list of '2-3 BALL' items 2 through to 3 matching the alias of 'BALL' would be returned. In this case: a small red ball, a large green ball.
Duplicate matching items will be removed from the results. With a word list of 'ALL GREEN BALL 2-3 BALL' then 'ALL GREEN BALL' would match: a small green ball, a large green ball and '2-3 BALL' would match: a small red ball, a large green ball. The results returned would be: a small green ball, a small red ball, a large green ball.
When matching an alias and zero or more qualifiers the first non-match will end the group. Given the word list 'RED BALL GREEN BALL', after identifying the alias 'BALL' and qualifier 'GREEN' the word 'BALL' fails to match as a qualifier. Therefore the first matching word group is 'GREEN BALL'. Matching then starts again to look for an alias for 'BALL' with a qualifier of 'RED'.
If a word fails to match as an alias, or fails to match as a qualifier after an alias match, it is added to the returned unknowns list. Consecutive unknown words are grouped together. Given the word list 'GREEN BALL BLUE FROG RED BALL', after identifying 'RED BALL' the word 'FROG' is not matched and added to the unknowns. Then 'BLUE' is also unmatched and the unknowns become 'BLUE FROG' because the unknowns are consecutive. Given the word list 'TREE GREEN BALL FROG RED BALL', then 'FROG' and 'TREE' would be unmatched. As they are not consecutive - 'GREEN BALL' would match between 'TREE' and 'FROG' two unknowns would be returned 'TREE' and 'FROG'.
There may be some instances where different matches need to be carried out against different Inventory. For example the PUT command. The PUT command takes the form: PUT <item ...> <container>. The container may be carried or at the current location, while items to put in it should be carried. In this instance the container can be checked by calling Match, the items can then be found by calling MatchAll with the word list returned by the initial Match to complete the matching. In this way different Inventory can be passed to Match and MatchAll.
Notes ¶
Bugs ¶
Terminal with is hardcoded to be 80 characters wide
If you examine another player you can see their inventory items. For now we only describe the inventory if not examining a player.
If a container is not collectable then it and its content will not be saved - even if it contains collectable items.
We don't treat observer differently to observers - should we?