Extract meat: Difference between revisions
imported>StDoodle Created page with '{{ #vardefine:name|extract_meat}}{{ #vardefine:return_type|int}}{{ FunctionPage| name={{#var:name}}| function_category=String Handling Routines| function1={{Function| name={{#v…' |
imported>Eliteofdelete No edit summary |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 5: | Line 5: | ||
FunctionPage| | FunctionPage| | ||
name={{#var:name}}| | name={{#var:name}}| | ||
function1={{Function| | function1={{Function| | ||
Line 16: | Line 15: | ||
}}| | }}| | ||
function_description=This function searches your supplied {{pspan|text}}, searching for either the phrase "You gain X Meat" or "You lose X Meat" and returns X. For "gain" X will be positive, and for "lose" negative. The number X can be formatted with or without commas. Note that the phrases to search are both case-sensitive (it will not match on "You gain 10 meat"). This function can be used for parsing meat gains and losses from combat and kmails (though | function_description=This function searches your supplied {{pspan|text}}, searching for either the phrase "You gain X Meat" or "You lose X Meat" and returns X. For "gain" X will be positive, and for "lose" negative. The number X can be formatted with or without commas. Note that the phrases to search are both case-sensitive (it will not match on "You gain 10 meat"). This function can be used for parsing meat gains and losses from combat and kmails (though additional parsing is necessary for kmail to avoid considering the text of the kmail itself, which could contain the meat gain/loss string).| | ||
code1={{CodeSample| | |||
title=Code Samples| | |||
description=| | |||
code= | |||
<syntaxhighlight> | |||
int meat; | |||
buffer fight = visit_url(to_url($location[The Castle in the Clouds in the Sky (Top Floor)])); | |||
repeat { | |||
if (contains_text(fight, "choice.php")) { //Check to see if in a choice adventure | |||
cli_execute("choice-goal"); //Clear the choice adventure | |||
fight = visit_url(to_url($location[The Castle in the Clouds in the Sky (Top Floor)])); | |||
} | |||
} until (!contains_text(fight, "choice.php")); | |||
fight = run_combat(); | |||
if (have_effect($effect[beaten up]) == 0) { | |||
meat = extract_meat(fight); | |||
print("You acquired the following amount of meat: "+meat, "blue"); | |||
} | |||
else print("You lost the fight :(", "red"); | |||
</syntaxhighlight>| | |||
moreinfo= | |||
Does not work with the adventure() function unless it calls a consult script. You must use a visit_url() or a consult script. | |||
}}| | |||
see_also={{SeeAlso|extract_items}}| | see_also={{SeeAlso|extract_items}}| | ||
special=This function returns 0 if it does not find a match. | special=This function returns 0 if it does not find a match. | ||
}} | }} | ||
[[Category:String Handling Routines]] |
Latest revision as of 08:51, 11 January 2015
Function Syntax
int extract_meat(string text )
- text is the string to search
This function searches your supplied text, searching for either the phrase "You gain X Meat" or "You lose X Meat" and returns X. For "gain" X will be positive, and for "lose" negative. The number X can be formatted with or without commas. Note that the phrases to search are both case-sensitive (it will not match on "You gain 10 meat"). This function can be used for parsing meat gains and losses from combat and kmails (though additional parsing is necessary for kmail to avoid considering the text of the kmail itself, which could contain the meat gain/loss string).
Code Samples
int meat;
buffer fight = visit_url(to_url($location[The Castle in the Clouds in the Sky (Top Floor)]));
repeat {
if (contains_text(fight, "choice.php")) { //Check to see if in a choice adventure
cli_execute("choice-goal"); //Clear the choice adventure
fight = visit_url(to_url($location[The Castle in the Clouds in the Sky (Top Floor)]));
}
} until (!contains_text(fight, "choice.php"));
fight = run_combat();
if (have_effect($effect[beaten up]) == 0) {
meat = extract_meat(fight);
print("You acquired the following amount of meat: "+meat, "blue");
}
else print("You lost the fight :(", "red");
Does not work with the adventure() function unless it calls a consult script. You must use a visit_url() or a consult script.
See Also
Special
This function returns 0 if it does not find a match.