Get property: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
imported>Eliteofdelete
No edit summary
imported>Fredg1
No edit summary
 
(5 intermediate revisions by 3 users not shown)
Line 15: Line 15:
}}|
}}|


function_description=Looks for a global or appropriate user preference from the saved files (found in your "Settings" directory) and if it finds one that matches, it returns whatever value is stored for that preference.|
function2={{Function|
name={{#var:name}}|
aggregate={{#var:aggregate}}|
return_type={{#var:return_type}}|
return_also={{#var:return_also}}|
parameter1={{Param|string|prop}}|
parameter2={{Param|boolean|global}}|
p1desc={{Pspan|prop}} is the property to get|
p2desc={{Pspan|global}}: Look for the property specifically in the global map if true, user map if false. If not included will check both.|
}}|
 
function_description=Looks for a global or appropriate user preference from the saved files (found in your "Settings" directory) and if it finds one that matches, it returns whatever value is stored for that preference. If a matching preference is not found, an empty string is returned.|


code1={{CodeSample|
code1={{CodeSample|
title=Code Samples|
title=Code Sample|
description=The following example adventures at the daily dungeon once a day if the property "_DailyDungeon" is false and the necessary items are gathered.  |
description=The following example adventures at the daily dungeon once a day if the property "dailyDungeonDone" is false and the necessary items are gathered.  |
code=
code=
<syntaxhighlight>
<syntaxhighlight>
if (!(to_boolean(get_property("_DailyDungeon")))) {
if (!(to_boolean(get_property("dailyDungeonDone")))) {
   if (can_interact()) {
   if (can_interact()) {
       cli_execute("find pick-o-matic lockpicks");
       cli_execute("find pick-o-matic lockpicks");
Line 37: Line 48:
       cli_execute("goal set fat loot token");
       cli_execute("goal set fat loot token");
       adventure(15, $location[The Daily Dungeon]);
       adventure(15, $location[The Daily Dungeon]);
      set_property("_DailyDungeon", true);
   }
   }
   else print("You do not have the required items for the Daily Dungeon.");
   else print("You do not have the required items for the Daily Dungeon.");
Line 44: Line 54:
</syntaxhighlight>|
</syntaxhighlight>|
moreinfo=
moreinfo=
Get_property always returns a string which in this example was converted to a boolean. Note: using an underscore before the property name resets the property's value to false each day.
Get_property always returns a string which in this example was converted to a boolean.
 
}}|
}}|


see_also={{SeeAlso|set_property}}|
see_also={{SeeAlso|Miscellaneous_Functions#Property_Functions}}|
cli_equiv=The CLI command "get" works similarly.|
cli_equiv=The CLI command "get" works similarly.|
special=If a matching preference is not found, this function returns an empty string.|
special=This function does NOT return an error if you misspelled a property's name, simply returning an empty string if no match was found.
This is mostly to accommodate for cases in the likes of an [[KoLmafia_Properties#User-defined_variables|user-made properties]] that was not set yet, especially for those starting with an underscore ( _ ), since they, lacking a default value, are being erased on rollover/ascension.|
}}
}}


[[Category:Miscellaneous Functions]]
[[Category:Miscellaneous Functions]]

Latest revision as of 20:40, 1 December 2019

Function Syntax

string get_property(string prop )

  • prop is the property to get

string get_property(string prop ,boolean global )

  • prop is the property to get
  • global: Look for the property specifically in the global map if true, user map if false. If not included will check both.

Looks for a global or appropriate user preference from the saved files (found in your "Settings" directory) and if it finds one that matches, it returns whatever value is stored for that preference. If a matching preference is not found, an empty string is returned.

Code Sample

The following example adventures at the daily dungeon once a day if the property "dailyDungeonDone" is false and the necessary items are gathered.

if (!(to_boolean(get_property("dailyDungeonDone")))) {
   if (can_interact()) {
      cli_execute("find pick-o-matic lockpicks");
      cli_execute("find eleven-foot pole"); 
      cli_execute("find ring of Detect Boring Doors");
   }
   if ((item_amount($item[pick-o-matic lockpicks]) > 0) && (item_amount($item[eleven-foot pole]) > 0) && (item_amount($item[ring of Detect Boring Doors]) > 0)) {
      equip($item[ring of Detect Boring Doors]);
      set_property("choiceAdventure692", 3);
      set_property("choiceAdventure693", 2);
      set_property("choiceAdventure690", 2);
      set_property("choiceAdventure691", 2);
      set_property("choiceAdventure689", 1);   
      cli_execute("goal set fat loot token");
      adventure(15, $location[The Daily Dungeon]);
   }
   else print("You do not have the required items for the Daily Dungeon.");
}
else print("You have already did the daily Dungeon today.");

Get_property always returns a string which in this example was converted to a boolean.

CLI Equivalent

The CLI command "get" works similarly.

See Also

Miscellaneous_Functions#Property_Functions()

Special

This function does NOT return an error if you misspelled a property's name, simply returning an empty string if no match was found. This is mostly to accommodate for cases in the likes of an user-made properties that was not set yet, especially for those starting with an underscore ( _ ), since they, lacking a default value, are being erased on rollover/ascension.