Difference between revisions of "Extract items"

From Kolmafia
Jump to navigation Jump to search
imported>Bale
(This should be the only problem. RFI removed.)
imported>Bale
m
Line 6: Line 6:
 
FunctionPage|
 
FunctionPage|
 
name={{#var:name}}|
 
name={{#var:name}}|
function_category=String Handling Routines|
 
  
 
function1={{Function|
 
function1={{Function|
Line 26: Line 25:
 
special=This function returns an empty map if it does not find any matches.
 
special=This function returns an empty map if it does not find any matches.
 
}}
 
}}
 +
 +
[[Category:String Handling Routines]]

Revision as of 05:09, 22 May 2010

needs(code_samples);

Function Syntax

int [item] extract_items(string text )

  • text is the string to search

This function searches your supplied text, searching for either the phrase "You acquire an item: <b>THING</b>" or "You acquire <b># THINGS</b>" and returns a map keyed by items ("THING"), with the quantity of each item as the value. Note that the phrases to search are case-sensitive, so it will not match on "You Acquire 10 broken skulls". This function can be used for parsing item acquisition from combat and kmails (though only the system messages are recommended from the latter, as the message text of a kmail can be set in a non-standard way).

If a kmail properly contains the text for item acquisition, this function will believe that the item was acquired. Consequently it should not be relied on in a case where a message containing text such as "You acquire an item: <b>Mr. Accessory<b>" will cost you. For secure sales you'll need to use contains_text() and a harder to forge string.

Note that this function cannot identify items affected by the sword behind inappropriate prepositions (acquired via pickpocketing, for instance). This has been reported as a bug and is subject to change.

See Also

extract_meat()

Special

This function returns an empty map if it does not find any matches.