Difference between pages "Ash Functions" and "Run choice"

From Kolmafia
(Difference between pages)
Jump to navigation Jump to search
(Use Template:FunctionEmbed for historical_age(), historical_price(), mall_price())
 
 
Line 1: Line 1:
{{TOCright}}
+
<onlyinclude>{{{{{format|Function2}}}
Master list of all ASH functions. All functions as of r20129 are listed; this list is intended to be kept current, but it is possible that some functions added since the above revision may be missing. (Please feel free to add in any you notice.)
+
|name=run_choice
The CLI command "[[ashref]]" shows every implemented ash function for your mafia version.
+
|function1.return_type=buffer
===a===
+
|function1.description=Run the current choice adventure by selecting a choice number.
{{FunctionEmbed|abort|format=signature}}
+
|function1.param1=choice
{{FunctionEmbed|add_item_condition|format=signature}}
+
|function1.param1.type=int
{{Flink|boolean|adv1|location|int|string}}
+
|function1.param1.description=the number of the choice option you wish to take. Use <code>-1</code> to automate the rest of the choice using the current [[Choice Adventures|choice adventure preferences]].
{{Flink|int|adv_cost|skill}}
+
|function1.param2=automate_fights
{{Flink|boolean|adventure|int|location|{{opt|string}}}}
+
|function1.param2.type=boolean
{{FunctionEmbed|all_monsters_with_id|format=signature}}
+
|function1.param2.optional=yes
{{Flink|string [int]|all_normal_outfits}}
+
|function1.param2.default=true
{{Flink|float [monster]|appearance_rates|location|{{opt|boolean}}}}
+
|function1.param2.description=If <code>true</code> and the choice resunts in a combat, KoLmafia will automate the fight. If <code>false</code>, KoLmafia will stop when the fight begins.
{{Flink|buffer|append|buffer|string}}
+
|function2.return_type=buffer
{{Flink|buffer|append_replacement|matcher|buffer|string}}
+
|function2.description=Run the current choice adventure by selecting a choice number and specifying additional URL parameters.
{{Flink|buffer|append_tail|matcher|buffer}}
+
|function2.param1=choice
{{Flink|buffer|attack}}
+
|function2.param1.type=int
{{Flink|boolean|autosell|int|item}}
+
|function2.param1.description=the number of the choice option you wish to take. Use <code>-1</code> to automate the rest of the choice using the current [[Choice Adventures|choice adventure preferences]].
{{Flink|int|autosell_price|item}}
+
|function2.param2=url_params
{{Flink|int|available_amount|item}}
+
|function2.param2.type=string
{{FunctionEmbed|available_choice_options}}
+
|function2.param2.description=URL parameter string to append when submitting the choice request.
 +
|description=
 +
<p>Proceeds to run a choice by selecting the provided choice number. If the provided number is <code>-1</code>, KoLmafia will use your current [[Choice Adventures|choice adventure preferences]]. This function returns the HTML of the choice result page (not just what is displayed, but all markup). This is most commonly used to finish up choices started via {{f|visit_url}}.</p>
  
===b===
+
<p>The second form (with the {{pspan|url_params}} parameter) can be used to automate fights that require additional URL parameters. For example, if you are in choice adventure #1182 and call <kbd>run_choice(1, "piece=1936")</kbd>, KoLmafia will send a request to the server using <samp>choice.php?option=1&pwd=<pwd_hash>&whichchoice=1182&piece=1936</samp>. You can specify multiple parameters separated by ampersands (<code>&</code>).</p>
{{Flink|boolean|batch_close}}
 
{{Flink|void|batch_open}}
 
{{Flink|boolean|bjornify_familiar|familiar}}
 
{{Flink|boolean|black_market_available}}
 
{{Flink|boolean|boolean_modifier|{{opt|string}}|string}}
 
{{Flink|boolean|boolean_modifier|item|string}}
 
{{Flink|int|buffed_hit_stat}}
 
{{FunctionEmbed|buffer_to_file|format=signature}}
 
{{Flink|boolean|buy|{{opt|coinmaster}}|int|item}}
 
{{Flink|int|buy|int|item|int}}
 
{{Flink|int|buy_price|coinmaster|item}}
 
{{Flink|boolean|buy_using_storage|int|item}}
 
{{Flink|int|buy_using_storage|int|item|int}}
 
{{Flink|boolean|buys_item|coinmaster|item}}
 
  
===c===
+
<p>A handy use for this function is to finish up choices that were started in the relay browser, or were interrupted (i.e. mafia aborted for you to manually make a choice selection).  Typing <kbd>ashq run_choice(choice)</kbd> into the gCLI will finish up the choice for you using your selected choice.  Note that <code>ashq</code> is necessary rather than <code>ash</code> to avoid spewing the entire choice results page into the gCLI.</p>
{{Flink|boolean|can_drink}}
 
{{Flink|boolean|can_eat}}
 
{{Flink|boolean|can_equip|item}}
 
{{Flink|boolean|can_faxbot|monster}}
 
{{Flink|boolean|can_interact}}
 
{{Flink|boolean|can_still_steal}}
 
{{Flink|boolean|canadia_available}}
 
{{Flink|item [0]|candy_for_tier|int|{{opt|int}}}}
 
{{Flink|int|ceil|float}}
 
{{Flink|boolean|change_mcd|int}}
 
{{Flink|string|char_at|string|int}}
 
{{Flink|void|chat_clan|string|{{opt|string}}}}
 
{{Flink|void|chat_macro|string}}
 
{{Flink|void|chat_notify|string|string}}
 
{{Flink|void|chat_private|string|string}}
 
{{Flink|boolean|chew|int|item}}
 
{{Flink|boolean|choice_follows_fight}}
 
{{Flink|class|class_modifier|string|string}}
 
{{Flink|class|class_modifier|item|string}}
 
{{Flink|void|clear|aggregate}}
 
{{FunctionEmbed|cli_execute|format=signature}}
 
{{FunctionEmbed|cli_execute_output|format=signature}}
 
{{Flink|int|closet_amount|item}}
 
{{Flink|int|combat_mana_cost_modifier}}
 
{{Flink|float|combat_rate_modifier}}
 
{{FunctionEmbed|contains_text|format=signature}}
 
{{Flink|void|council}}
 
{{Flink|int|count|aggregate}}
 
{{Flink|boolean|craft|string|int|item|item}}
 
{{Flink|string|craft_type|item}}
 
{{Flink|int|creatable_amount|item}}
 
{{Flink|int|creatable_turns|{{opt|item}}|{{opt|int}}|{{opt|boolean}}}}
 
{{Flink|boolean|create|int|item}}
 
{{Flink|matcher|create_matcher|string|string}}
 
{{Flink|stat|current_hit_stat}}
 
{{Flink|int|current_mcd}}
 
{{Flink|int [string]|current_pvp_stances}}
 
{{Flink|int|current_rad_sickness}}
 
{{Flink|int|current_round}}
 
  
===d===
+
<p>The second form was added in [https://kolmafia.us/threads/19537-law-of-averages-is-reusable-add-ability-to-specify-extra-fields-when-automati.24204/ r19537].</p>
{{Flink|element|dad_sea_monkee_weakness|int}}
+
|code1={{CodeSample
{{Flink|item|daily_special}}
+
  |title=Code Samples
{{Flink|float|damage_absorption_percent}}
+
  |description=This is a personalized version of {{f|adv1}} that is capable of returning information about which adventure is encountered so that you can look for a specific choice adventure. If a choice is encountered, it selects the appropriate choice per your settings for that choice adventure, and assigns the results to the <code>page_text</code> variable. (Effectively the same as using <code>run_choice(-1)</code>). If a combat is encountered instead of a choice adventure, {{f|run_combat}} is used.
{{Flink|int|damage_reduction}}
+
  |code=
{{Flink|buffer|delete|buffer|int|int}}
+
{{{!}} class="wikitable"
{{Flink|effect|desc_to_effect|string}}
+
! style="width: 50%" {{!}} ASH
{{Flink|item|desc_to_item|string}}
+
! style="width: 50%" {{!}} JavaScript
{{Flink|void|disable|string}}
+
{{!}}- style="vertical-align: top"
{{Flink|boolean|dispensary_available}}
+
{{!}}
{{Flink|int|display_amount|item}}
+
<syntaxhighlight lang="d" line highlight="14">
{{Flink|boolean|drink|int|item}}
+
int run_adv( location place ) {
{{Flink|boolean|drinksilent|item|{{opt|int}}}}
+
  string page_text = to_url( place ).visit_url();
 +
  string choiceAdventure = "-1";
 +
  matcher m_choice = create_matcher( "whichchoice value=(\\d+)", page_text );
 +
  while ( page_text.contains_text( "choice.php" ) ) {
 +
      m_choice.reset( page_text );
 +
      m_choice.find();
 +
      choiceAdventure = m_choice.group( 1 );
 +
      string choice_num = get_property( "choiceAdventure" + choiceAdventure );
  
===e===
+
      if ( choice_num == "0" ) abort( "Manual control for " + choiceAdventure );
{{Flink|boolean|eat|int|item}}
+
      if ( choice_num == "" ) abort( "Unsupported choice adventure!" );
{{Flink|boolean|eatsilent|int|item}}
 
{{Flink|effect|effect_modifier|string|string}}
 
{{Flink|effect|effect_modifier|item|string}}
 
{{Flink|float|elemental_resistance|element}}
 
{{Flink|float|elemental_resistance|{{opt|monster}}}}
 
{{Flink|boolean|empty_closet}}
 
{{Flink|void|enable|string}}
 
{{Flink|int|end|matcher|{{opt|int}}}}
 
{{FunctionEmbed|ends_with|format=signature}}
 
{{Flink|boolean|enthrone_familiar|familiar}}
 
{{Flink|string|entity_decode|string}}
 
{{Flink|string|entity_encode|string}}
 
{{Flink|boolean|equip|{{opt|slot}}|item}}
 
{{Flink|boolean|equip_all_familiars}}
 
{{Flink|int|equipped_amount|item}}
 
{{Flink|item|equipped_item|slot}}
 
{{Flink|string|eudora}}
 
{{Flink|boolean|eudora|string}}
 
{{Flink|string|every_card_name|strict_string}}
 
{{Flink|int|expected_damage|{{opt|monster}}}}
 
{{Flink|float|experience_bonus}}
 
{{Flink|float|expression_eval}}
 
{{Flink|int [item]|extract_items|string}}
 
{{Flink|int|extract_meat|string}}
 
  
===f===
+
      page_text = run_choice( choice_num );
{{Flink|item|familiar_equipment|familiar}}
+
  }
{{Flink|item|familiar_equipped_equipment|familiar}}
+
  if ( page_text.contains_text( "Combat" ) )
{{Flink|int|familiar_weight|familiar}}
+
      run_combat();
{{Flink|boolean [familiar]|favorite_familiars|}}
+
  return choiceAdventure.to_int();
{{Flink|boolean|faxbot|monster}}
+
}
{{Flink|boolean|fight_follows_choice}}
+
</syntaxhighlight>
{{FunctionEmbed|file_to_array|format=signature}}
+
{{!}}
{{FunctionEmbed|file_to_buffer|format=signature}}
+
<syntaxhighlight lang="js" line highlight="14">
{{Flink|boolean|file_to_map|string|aggregate|{{opt|boolean}}}}
+
const {abort, getProperty, toUrl, visitUrl} = require("kolmafia");
{{Flink|boolean|find|matcher}}
 
{{Flink|int|floor|float}}
 
{{Flink|boolean|florist_available}}
 
{{Flink|boolean|flush_monster_manuel_cache}}
 
{{Flink|string|form_field|string}}
 
{{Flink|string [string]|form_fields}}
 
{{Flink|string|format_date_time|string|string|string}}
 
{{Flink|boolean|friars_available}}
 
{{Flink|int|fuel_cost|skill}}
 
{{Flink|int|fullness_limit}}
 
  
===g===
+
function runAdv(place) {
{{Flink|boolean|galaktik_cures_discounted}}
+
  const pageText = visitUrl(toUrl(place));
{{Flink|int|gameday_to_int}}
+
  let choiceAdventure = -1;
{{Flink|string|gameday_to_string}}
+
  while (pageText.includes("choice.php")) {
{{Flink|int|gametime_to_int}}
+
    let match = pageText.match(/whichchoice value=(\d+)/);
{{Flink|boolean [string] |get_all_properties|string|boolean}}
+
    choiceAdventure = parseInt(match[1]);
{{Flink|int|get_auto_attack}}
+
    let choiceNum = Number(getProperty("choiceAdventure" + choiceAdventure));
{{Flink|int [item]|get_campground}}
 
{{Flink|string |get_ccs_action|int}}
 
{{Flink|int [item]|get_chateau}}
 
{{Flink|int|get_clan_id}}
 
{{Flink|int [item]|get_clan_lounge}}
 
{{Flink|string|get_clan_name}}
 
{{Flink|int [string]|get_clan_rumpus}}
 
{{Flink|int [item]|get_closet}}
 
{{Flink|string|get_counters|string|int|int}}
 
{{Flink|string [int]|get_custom_outfits}}
 
{{Flink|item|get_dwelling}}
 
{{Flink|string [location, 3]|get_florist_plants}}
 
{{Flink|int [item]|get_free_pulls}}
 
{{Flink|int|get_fuel}}
 
{{Flink|string [int]|get_goals}}
 
{{Flink|boolean|get_ignore_zone_warnings}}
 
{{Flink|int [item]|get_ingredients|item}}
 
{{Flink|int [item]|get_inventory}}
 
{{Flink|boolean [monster]|get_location_monsters|location}}
 
{{Flink|monster [monster]|get_monster_mapping|{{opt|string}}}}
 
{{Flink|monster [int]|get_monsters|location}}
 
{{Flink|string [int]|get_moods}}
 
{{Flink|string [int]|get_outfits}}
 
{{Flink|string|get_path}}
 
{{Flink|string|get_path_full}}
 
{{Flink|string|get_path_variables}}
 
{{Flink|string|get_player_id|string}}
 
{{Flink|string|get_player_name|int}}
 
{{Flink|int|get_power|item}}
 
{{Flink|string|get_property|string|{{opt|boolean}}}}
 
{{Flink|int [item]|get_related|item|string}}
 
{{Flink|int|get_revision}}
 
{{Flink|int [item]|get_shop}}
 
{{Flink|string [0]|get_shop_log}}
 
{{Flink|{string file; string name; int line;} [0]|get_stack_trace}}
 
{{Flink|{int [item]|get_stash}}
 
{{Flink|int [item]|get_storage}}
 
{{Flink|string|get_version}}
 
{{Flink|boolean|gnomads_available}}
 
{{Flink|boolean|goal_exists|string}}
 
{{Flink|string|group|matcher|{{opt|int}}}}
 
{{Flink|int|group_count|matcher}}
 
{{Flink|boolean [string]|group_names|matcher}}
 
{{Flink|string [int, int]|group_string|string|string}}
 
{{Flink|boolean|guild_store_available}}
 
  
===h===
+
    if (choiceNum === 0) abort("Manual control for " + choiceAdventure);
{{Flink|boolean|handling_choice}}
+
    if (Number.isNaN(choiceNum)) abort("Unsupported choice adventure!");
{{Flink|boolean|have_bartender}}
 
{{Flink|boolean|have_chef}}
 
{{Flink|boolean|have_display}}
 
{{Flink|int|have_effect|effect}}
 
{{Flink|boolean|have_equipped|item}}
 
{{Flink|boolean|have_familiar|familiar}}
 
{{Flink|boolean|have_mushroom_plot}}
 
{{Flink|boolean|have_outfit|string}}
 
{{Flink|boolean|have_servant|servant}}
 
{{Flink|boolean|have_shop}}
 
{{Flink|boolean|have_skill|skill}}
 
{{Flink|boolean|hedge_maze|string}}
 
{{Flink|boolean|hermit|int|item}}
 
{{Flink|boolean|hidden_temple_unlocked}}
 
{{Flink|boolean|hippy_stone_broken}}
 
{{Flink|boolean|hippy_store_available}}
 
{{FunctionEmbed|historical_age}}
 
{{FunctionEmbed|historical_price}}
 
{{Flink|string|holiday}}
 
{{Flink|int|hp_cost|skill}}
 
  
===i===
+
    pageText = runChoice(choiceNum);
{{Flink|monster|image_to_monster|strict_string}}
+
  }
{{Flink|boolean|in_bad_moon}}
+
  if (pageText.includes("Combat"))
{{Flink|boolean|in_hardcore}}
+
    runCombat();
{{Flink|boolean|in_moxie_sign}}
+
  return choiceAdventure;
{{Flink|boolean|in_multi_fight}}
+
}
{{Flink|boolean|in_muscle_sign}}
+
</syntaxhighlight>
{{Flink|boolean|in_mysticality_sign}}
+
{{!}}}
{{Flink|string|inaccessible_reason|coinmaster}}
+
  |moreinfo=
{{FunctionEmbed|index_of|format=signature}}
+
}}
{{Flink|int|inebriety_limit}}
+
|see_also={{SeeAlso|adventure|adv1|visit_url|run_combat|run_turn}}
{{Flink|float|initiative_modifier}}
+
|cli_equiv=The CLI command <kbd>choice</kbd> works similarly.
{{Flink|buffer|insert|buffer|int|string}}
+
|more_info=
{{Flink|boolean|is_accessible|coinmaster}}
+
|special=
{{Flink|boolean|is_banished|monster}}
+
|{{{1|}}}
{{Flink|boolean|is_coinmaster_item|item}}
+
}}</onlyinclude>
{{FunctionEmbed|is_dark_mode}}
+
[[Category:Adventuring]]
{{Flink|boolean|is_discardable|item}}
 
{{Flink|boolean|is_displayable|item}}
 
{{Flink|boolean|is_familiar_equipment_locked}}
 
{{Flink|boolean|is_giftable|item}}
 
{{Flink|boolean|is_goal|item}}
 
{{Flink|boolean|is_integer|string}}
 
{{Flink|boolean|is_npc_item|item}}
 
{{Flink|boolean|is_online|string}}
 
{{Flink|boolean|is_tradeable|item}}
 
{{Flink|boolean|is_trendy|item/familiar/skill/string}}
 
{{Flink|boolean|is_unrestricted|item/familiar/skill/string}}
 
{{Flink|boolean|is_wearing_outfit|string}}
 
{{Flink|int|item_amount|item}}
 
{{Flink|float|item_drop_modifier}}
 
{{Flink|int [item]|item_drops|{{opt|monster}}}}
 
{{Flink|record [int]|item_drops_array|{{opt|monster}}}}
 
{{Flink|string|item_type|item}}
 
 
 
===j===
 
{{flink|int|jump_chance|{{opt|monster}}|{{opt|int}}|{{opt|int}}}}
 
{{flink|int|jump_chance|location|{{opt|int}}|{{opt|int}}}}
 
 
 
===k===
 
{{flink|boolean|knoll_available}}
 
 
 
===l===
 
{{Flink|int|last_choice}}
 
{{Flink|int|last_decision}}
 
{{FunctionEmbed|last_index_of|format=signature}}
 
{{Flink|string|last_item_message}}
 
{{Flink|monster|last_monster}}
 
{{Flink|string|last_skill_message}}
 
{{Flink|string|leetify|string}}
 
{{Flink|int|length|string}}
 
{{Flink|int|lightning_cost}}
 
{{Flink|string|limit_mode}}
 
{{Flink|buffer|load_html|string}}
 
{{Flink|void|lock_familiar_equipment|boolean}}
 
{{Flink|void|logprint|string}}
 
 
 
===m===
 
{{Flink|string|make_url|string|boolean|boolean}}
 
{{FunctionEmbed|mall_price}}
 
{{FunctionEmbed|mall_prices}}
 
{{Flink|int|mana_cost_modifier}}
 
{{Flink|boolean|map_to_file|aggregate|string|{{opt|boolean}}}}
 
{{Flink|float|max|float|float}}
 
{{Flink|int|max|int|int}}
 
{{Flink|boolean|maximize|string|boolean}}
 
{{Flink|boolean|maximize|string|int|int|boolean}}
 
{{Flink|record [int]|maximize|string|int|int|boolean|boolean}}
 
{{Flink|int|meat_drop|{{opt|monster}}}}
 
{{Flink|float|meat_drop_modifier}}
 
{{Flink|float|min|float|float}}
 
{{Flink|int|min|int|int}}
 
{{Flink|item|minstrel_instrument}}
 
{{Flink|int|minstrel_level}}
 
{{Flink|boolean|minstrel_quest}}
 
{{Flink|float|modifier_eval|string}}
 
{{Flink|int|monster_attack|{{opt|monster}}}}
 
{{Flink|int|monster_defense|{{opt|monster}}}}
 
{{Flink|element|monster_element|{{opt|monster}}}}
 
{{Flink|float|monster_eval|string}}
 
{{Flink|int|monster_factoids_available|monster|boolean}}
 
{{Flink|int|monster_hp|{{opt|monster}}}}
 
{{Flink|int|monster_initiative|{{opt|monster}}}}
 
{{Flink|int|monster_level_adjustment}}
 
{{Flink|string|monster_manuel_text|monster}}
 
{{Flink|phylum|monster_phylum|{{opt|monster}}}}
 
{{Flink|void|mood_execute}}
 
{{Flink|string [0]|mood_list}}
 
{{Flink|int|moon_light}}
 
{{Flink|int|moon_phase}}
 
{{Flink|int|mp_cost|skill}}
 
{{Flink|int|my_absorbs}}
 
{{Flink|int|my_adventures}}
 
{{Flink|int|my_ascensions}}
 
{{Flink|int|my_audience}}
 
{{Flink|int|my_basestat|stat}}
 
{{Flink|familiar|my_bjorned_familiar}}
 
{{Flink|int|my_buffedstat|stat}}
 
{{Flink|class|my_class}}
 
{{Flink|int|my_closet_meat}}
 
{{Flink|string|my_companion}}
 
{{Flink|int|my_daycount}}
 
{{Flink|int|my_discomomentum}}
 
{{Flink|familiar|my_effective_familiar}}
 
{{Flink|int [effect]|my_effects}}
 
{{Flink|familiar|my_enthroned_familiar}}
 
{{Flink|familiar|my_familiar}}
 
{{Flink|int|my_fullness}}
 
{{Flink|int|my_fury}}
 
{{Flink|string|my_garden_type}}
 
{{Flink|string|my_hash}}
 
{{Flink|int|my_hp}}
 
{{Flink|string|my_id}}
 
{{Flink|int|my_inebriety}}
 
{{Flink|int|my_level}}
 
{{Flink|int|my_lightning}}
 
{{Flink|location|my_location}}
 
{{Flink|string|my_mask}}
 
{{Flink|int|my_maxfury}}
 
{{Flink|int|my_maxhp}}
 
{{Flink|int|my_maxmp}}
 
{{Flink|int|my_maxpp}}
 
{{Flink|int|my_meat}}
 
{{Flink|int|my_mp}}
 
{{Flink|string|my_name}}
 
{{Flink|string|my_path}}
 
{{Flink|familiar|my_poke_fam}}
 
{{Flink|int|my_pp}}
 
{{Flink|stat|my_primestat}}
 
{{Flink|int|my_rain}}
 
{{Flink|servant|my_servant|servant}}
 
{{Flink|int|my_session_adv}}
 
{{Flink|int [item]|my_session_items}}
 
{{Flink|int|my_session_meat}}
 
{{Flink|string|my_sign}}
 
{{Flink|int|my_soulsauce}}
 
{{Flink|int|my_spleen_use}}
 
{{Flink|int|my_storage_meat}}
 
{{Flink|thrall|my_thrall}}
 
{{Flink|int|my_thunder}}
 
{{Flink|int|my_turncount}}
 
{{Flink|vykea|my_vykea_companion}}
 
 
 
===n===
 
{{Flink|float|now_to_string|string}}
 
{{Flink|int|npc_price|item}}
 
{{Flink|string|numberology_prize|int}}
 
{{Flink|float|numeric_modifier|{{opt|string}}|string}}
 
{{Flink|float|numeric_modifier|item|string}}
 
{{Flink|float|numeric_modifier|effect|string}}
 
{{Flink|float|numeric_modifier|skill|string}}
 
{{Flink|float|numeric_modifier|familiar|string|int|item}}
 
 
 
===o===
 
{{Flink|boolean|outfit|string}}
 
{{Flink|item [int]|outfit_pieces|string}}
 
{{Flink|string|outfit_tattoo|{{opt|string}}}}
 
{{FunctionEmbed|overdrink|format=signature}}
 
 
 
===p===
 
{{Flink|void|print|string|{{opt|string}}}}
 
{{Flink|void|print_html|string}}
 
{{FunctionEmbed|property_default_value|format=signature}}
 
{{FunctionEmbed|property_exists|format=signature}}
 
{{FunctionEmbed|property_has_default|format=signature}}
 
{{Flink|int|pulls_remaining}}
 
{{Flink|boolean|put_closet|int|{{opt|item}}}}
 
{{Flink|boolean|put_display|int|item}}
 
{{Flink|boolean|put_shop|int|int|{{opt|int}}|item}}
 
{{Flink|boolean|put_shop_using_storage|int|int|{{opt|int}}|item}}
 
{{Flink|boolean|put_stash|int|item}}
 
{{Flink|int|pvp_attacks_left}}
 
 
 
===r===
 
{{Flink|int|rain_cost|skill}}
 
{{Flink|int|random|int}}
 
{{Flink|int|raw_damage_absorption}}
 
{{Flink|void|refresh_shop}}
 
{{Flink|void|refresh_stash}}
 
{{Flink|void|refresh_status}}
 
{{Flink|void|remove_item_condition|int|item}}
 
{{FunctionEmbed|remove_property|format=signature}}
 
{{FunctionEmbed|rename_property|format=signature}}
 
{{Flink|boolean|replace|buffer|int|int|string}}
 
{{Flink|string|replace_all|matcher|string}}
 
{{Flink|string|replace_first|matcher|string}}
 
{{Flink|buffer|replace_string|buffer|string|string}}
 
{{Flink|buffer|replace_string|string|string|string}}
 
{{Flink|boolean|reprice_shop|int|{{opt|int}}|item}}
 
{{Flink|matcher|reset|matcher|{{opt|string}}}}
 
{{Flink|boolean|restore_hp|int}}
 
{{Flink|boolean|restore_mp|int}}
 
{{Flink|boolean|retrieve_item|int|item}}
 
{{Flink|int [int]|reverse_numberology|{{opt|int|int}}}}
 
{{Flink|int|rollover}}
 
{{Flink|int|round|float}}
 
{{Flink|buffer|run_choice|int}}
 
{{Flink|buffer|run_combat|{{opt|string}}}}
 
{{Flink|buffer|run_turn}}
 
{{Flink|buffer|runaway}}
 
 
 
===s===
 
{{Flink|boolean|sell|coinmaster|int|item}}
 
{{Flink|int|sell_price|coinmaster|item}}
 
{{Flink|boolean|sells_item|coinmaster|item}}
 
{{Flink|string [int]|session_logs|{{opt|string}}|int}}
 
{{Flink|void|set_auto_attack|int}}
 
{{Flink|void|set_length|buffer|int}}
 
{{Flink|void|set_location|location}}
 
{{Flink|void|set_property|string|string}}
 
{{Flink|int|shop_amount|item}}
 
{{Flink|int|shop_price|item}}
 
{{Flink|skill|skill_modifier|string|string}}
 
{{Flink|int|slash_count|item}}
 
{{Flink|int|soulsauce_cost|skill}}
 
{{Flink|int|spleen_limit}}
 
{{Flink|string [int]|split_string|string|{{opt|string}}}}
 
{{Flink|float|square_root|float}}
 
{{Flink|int|start|matcher|{{opt|int}}}}
 
{{FunctionEmbed|starts_with|format=signature}}
 
{{Flink|int|stash_amount|item}}
 
{{Flink|stat|stat_bonus_today}}
 
{{Flink|stat|stat_bonus_tomorrow}}
 
{{Flink|stat|stat_modifier|effect|string}}
 
{{Flink|buffer|steal}}
 
{{Flink|int|stills_available}}
 
{{Flink|void|stop_counter|string}}
 
{{Flink|int|storage_amount|item}}
 
{{Flink|string|string_modifier|{{opt|string}}|string}}
 
{{Flink|skill|stun_skill}}
 
{{Flink|string|substring|string|int|{{opt|int}}}}
 
{{Flink|boolean|svn_at_head|string}}
 
{{Flink|boolean|svn_exists|string}}
 
{{Flink|record|svn_info|string}}
 
{{Flink|boolean|sweet_synthesis|effect}}
 
{{Flink|item [0]|sweet_synthesis_pair|effect}}
 
{{Flink|effect|sweet_synthesis_result|item|item}}
 
 
 
===t===
 
{{Flink|boolean|take_closet|int|{{opt|item}}}}
 
{{Flink|boolean|take_display|int|item}}
 
{{Flink|boolean|take_shop|{{opt|int}}|item}}
 
{{Flink|boolean|take_stash|int|item}}
 
{{Flink|boolean|take_storage|int|item}}
 
{{Flink|int|tavern|{{opt|string}}}}
 
{{Flink|buffer|throw_item|item}}
 
{{Flink|buffer|throw_items|item|item}}
 
{{Flink|int|thunder_cost|skill}}
 
{{Flink|buffer|time_to_string}}
 
{{Flink|boolean|to_boolean|any}}
 
{{Flink|bounty|to_bounty|strict_string}}
 
{{Flink|class|to_class|strict_string/int}}
 
{{Flink|coinmaster|to_coinmaster|strict_string}}
 
{{Flink|effect|to_effect|int}}
 
{{Flink|effect|to_effect|strict_string}}
 
{{Flink|effect|to_effect|skill}}
 
{{Flink|element|to_element|strict_string}}
 
{{Flink|familiar|to_familiar|int}}
 
{{Flink|familiar|to_familiar|strict_string}}
 
{{Flink|float|to_float|any}}
 
{{Flink|int|to_int|any}}
 
{{Flink|item|to_item|strict_string}}
 
{{Flink|item|to_item|int}}
 
{{Flink|item|to_item|string|int}}
 
{{Flink|string|to_json|aggregate}}
 
{{Flink|location|to_location|strict_string}}
 
{{Flink|location|to_location|int}}
 
{{Flink|string|to_lower_case|string}}
 
{{Flink|monster|to_monster|strict_string}}
 
{{Flink|phylum|to_phylum|string}}
 
{{Flink|string|to_plural|item}}
 
{{Flink|servant|to_servant|int}}
 
{{Flink|servant|to_servant|strict_string}}
 
{{Flink|skill|to_skill|effect}}
 
{{Flink|skill|to_skill|int}}
 
{{Flink|skill|to_skill|strict_string}}
 
{{Flink|slot|to_slot|item}}
 
{{Flink|skill|to_slot|strict_string}}
 
{{Flink|stat|to_stat|string}}
 
{{Flink|string|to_string|any}}
 
{{Flink|thrall|to_thrall|{{opt|string}}|{{opt|int}}}}
 
{{Flink|string|to_upper_case|string}}
 
{{Flink|string|to_url|location}}
 
{{Flink|vykea|to_vykea|strict_string}}
 
{{Flink|string|today_to_string}}
 
{{Flink|int|total_free_rests}}
 
{{Flink|int|total_turns_played}}
 
{{Flink|boolean|tower_door}}
 
{{Flink|void|traceprint|string}}
 
{{Flink|int|truncate|float}}
 
{{Flink|int|turns_per_cast|skill}}
 
{{Flink|int|turns_played}}
 
 
 
===u===
 
{{Flink|string|url_decode|string}}
 
{{Flink|string|url_encode|string}}
 
{{Flink|boolean|use|int|item}}
 
{{Flink|boolean|use_familiar|familiar}}
 
{{Flink|boolean|use_servant|servant}}
 
{{Flink|boolean|use_skill|int|skill|{{opt|string}}}}
 
{{Flink|buffer|use_skill|skill}}
 
{{Flink|boolean|user_confirm|string}}
 
{{Flink|boolean|user_confirm|string|int|boolean}}
 
 
 
===v===
 
{{Flink|boolean|visit|coinmaster}}
 
{{FunctionEmbed|visit_url}}
 
 
 
===w===
 
{{Flink|void|wait|int}}
 
{{Flink|void|waitq|int}}
 
{{Flink|int|weapon_hands|item}}
 
{{Flink|stat|weapon_type|item}}
 
{{Flink|int|weight_adjustment}}
 
{{Flink|boolean|white_citadel_available}}
 
{{Flink|boolean [string]|who_clan|{{opt|string}}}}
 
{{Flink|boolean|will_usually_dodge}}
 
{{Flink|boolean|will_usually_miss}}
 
{{Flink|void|write|string}}
 
{{Flink|void|writeln|string}}
 
 
 
===x===
 
{{Flink|string[int]|xpath|string|string}}
 
 
 
[[Category:Scripting]]
 

Revision as of 19:45, 1 January 2021

Function Syntax

buffer run_choiceint choice, boolean? automate_fights = true )

Run the current choice adventure by selecting a choice number.
  • choice: the number of the choice option you wish to take. Use -1 to automate the rest of the choice using the current choice adventure preferences.
  • automate_fights: If true and the choice resunts in a combat, KoLmafia will automate the fight. If false, KoLmafia will stop when the fight begins.

buffer run_choiceint choice, string url_params )

Run the current choice adventure by selecting a choice number and specifying additional URL parameters.
  • choice: the number of the choice option you wish to take. Use -1 to automate the rest of the choice using the current choice adventure preferences.
  • url_params: URL parameter string to append when submitting the choice request.

Proceeds to run a choice by selecting the provided choice number. If the provided number is -1, KoLmafia will use your current choice adventure preferences. This function returns the HTML of the choice result page (not just what is displayed, but all markup). This is most commonly used to finish up choices started via visit_url().

The second form (with the url_params parameter) can be used to automate fights that require additional URL parameters. For example, if you are in choice adventure #1182 and call run_choice(1, "piece=1936"), KoLmafia will send a request to the server using choice.php?option=1&pwd=<pwd_hash>&whichchoice=1182&piece=1936. You can specify multiple parameters separated by ampersands (&).

A handy use for this function is to finish up choices that were started in the relay browser, or were interrupted (i.e. mafia aborted for you to manually make a choice selection). Typing ashq run_choice(choice) into the gCLI will finish up the choice for you using your selected choice. Note that ashq is necessary rather than ash to avoid spewing the entire choice results page into the gCLI.

The second form was added in r19537.

Code Samples

This is a personalized version of adv1() that is capable of returning information about which adventure is encountered so that you can look for a specific choice adventure. If a choice is encountered, it selects the appropriate choice per your settings for that choice adventure, and assigns the results to the page_text variable. (Effectively the same as using run_choice(-1)). If a combat is encountered instead of a choice adventure, run_combat() is used.

ASH JavaScript
 1 int run_adv( location place ) {
 2    string page_text = to_url( place ).visit_url();
 3    string choiceAdventure = "-1";
 4    matcher m_choice = create_matcher( "whichchoice value=(\\d+)", page_text );
 5    while ( page_text.contains_text( "choice.php" ) ) {
 6       m_choice.reset( page_text );
 7       m_choice.find();
 8       choiceAdventure = m_choice.group( 1 );
 9       string choice_num = get_property( "choiceAdventure" + choiceAdventure );
10 
11       if ( choice_num == "0" ) abort( "Manual control for " + choiceAdventure );
12       if ( choice_num == "" ) abort( "Unsupported choice adventure!" );
13 
14       page_text = run_choice( choice_num );
15    }
16    if ( page_text.contains_text( "Combat" ) )
17       run_combat();
18    return choiceAdventure.to_int();
19 }
 1 const {abort, getProperty, toUrl, visitUrl} = require("kolmafia");
 2 
 3 function runAdv(place) {
 4   const pageText = visitUrl(toUrl(place));
 5   let choiceAdventure = -1;
 6   while (pageText.includes("choice.php")) {
 7     let match = pageText.match(/whichchoice value=(\d+)/);
 8     choiceAdventure = parseInt(match[1]);
 9     let choiceNum = Number(getProperty("choiceAdventure" + choiceAdventure));
10 
11     if (choiceNum === 0) abort("Manual control for " + choiceAdventure);
12     if (Number.isNaN(choiceNum)) abort("Unsupported choice adventure!");
13 
14     pageText = runChoice(choiceNum);
15   }
16   if (pageText.includes("Combat"))
17     runCombat();
18   return choiceAdventure;
19 }

CLI Equivalent

The CLI command choice works similarly.

See Also

adventure() | adv1() | visit_url() | run_combat() | run_turn()