MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame^] | 1 | int parse_command(string str, mixed source, string pattern, var1, var2 ...); |
| 2 | |
| 3 | Parses commands given in "str" against the pattern in "pattern" and |
| 4 | returns 1 if it matches. "source" is either an object or an array of objects. |
| 5 | This is essentially a 'hotted' sscanf and it has a similar syntax, although |
| 6 | parse_command works on word basis where sscanf works on character basis. |
| 7 | |
| 8 | .ip str |
| 9 | Given command |
| 10 | .ip source |
| 11 | Either an array holding the accessible objects, or |
| 12 | an object from which to recurse and create |
| 13 | the list of accessible objects, normally |
| 14 | ob = environment(this_player()) . |
| 15 | |
| 16 | .ip pattern |
| 17 | Parse pattern as list of words and formats: |
| 18 | .nf |
| 19 | Syntax: |
| 20 | 'word' obligatory text (One word) |
| 21 | [word] optional text (One word) |
| 22 | / Alternative marker |
| 23 | %o Single item, object |
| 24 | %l Single living object |
| 25 | %s Any text (multiple words) |
| 26 | %w Any word |
| 27 | %p Preposition |
| 28 | %i Any items |
| 29 | %d Number 0- or tx(0-99) |
| 30 | .fi |
| 31 | Example string: " 'get' / 'take' %i " . |
| 32 | Items as in %o and %i can on many forms, some examples: |
| 33 | .nf |
| 34 | apple, two apples, twentyfirst apple |
| 35 | apples, all apples, all green apples, all green ones |
| 36 | .fi |
| 37 | |
| 38 | .ip varN |
| 39 | This is the list of result variables as in sscanf. |
| 40 | One variable is needed for each %_. |
| 41 | The return types of different %_ is: |
| 42 | .nf |
| 43 | %o Returns an object |
| 44 | %l Returns an object |
| 45 | %s Returns a string of words |
| 46 | %w Returns a string of one word |
| 47 | %p Can on entry hold a list of word in array |
| 48 | or an empty variable |
| 49 | Returns: |
| 50 | if empty variable: a string |
| 51 | if array: array[0]=matched word |
| 52 | %i Returns a special array on the form: |
| 53 | [0] = (int) given numeric prefix |
| 54 | =0: all or a pluralform given |
| 55 | >0: numeral given: two, three, four... |
| 56 | <0: order given: second, third ... |
| 57 | [1..n] (object) Objectpointers |
| 58 | A list of the POSSIBLE objects that can match |
| 59 | the given %i. No choosing of third or such. |
| 60 | %d Returns a number |
| 61 | .fi |
| 62 | .lp |
| 63 | Example: |
| 64 | |
| 65 | a=parse_command("take apple",environment(this_player()), |
| 66 | " 'get' / 'take' %i ",items); |
| 67 | |
| 68 | HISTORY |
| 69 | LDMud 3.3.258 and LP "03.02.1@150" removed the compat-mode |
| 70 | parse_command(). |
| 71 | |
| 72 | 29.10.2006 Zesstra |