Difference between pages "Historical age" and "Mall price"

From Kolmafia
(Difference between pages)
Jump to navigation Jump to search
m
 
(Convert to Template:Function2 format, use Template:SeeAlso/Mall Prices, add JS sample code)
 
Line 1: Line 1:
 
<onlyinclude>{{{{{format|Function2}}}
 
<onlyinclude>{{{{{format|Function2}}}
|name=historical_age
+
|name=mall_price
|function1.return_type=float
+
|function1.return_type=
|function1.description=Returns the age of the price returned by {{f|historical_age}} in days.
+
|function1.description=Returns the current mall price of the given item
 
|function1.param1=shop_for
 
|function1.param1=shop_for
 
|function1.param1.type=item
 
|function1.param1.type=item
|function1.param1.description=Item to check for
+
|function1.param1.description=Item to search for
|description=The return value is in days. For example, a return value of 0.5 means that the price is 12 hours old.
+
|description=
 +
Returns the current mall price of the given item, ignoring the first five items listed to compensate for stores with limits and min-priced sales. To prevent abuse, this will only perform an actual Mall search once per item per session; subsequent calls for the same item will return a cached value. The cache will be updated after attempts to purchase the item using the CLI or ASH {{f|buy}} command (even unsuccessful ones), but not in ''any'' other conditions, including purchasing with the purchase tab.
 
|code1={{CodeSample
 
|code1={{CodeSample
 
   |title=Code Samples
 
   |title=Code Samples
   |description=This function returns a price no more than 18 hours old by checking {{f|mall_price}} if {{f|historical_price}} is older than that.
+
   |description=Creates Mae Wests based on your stills remaining. Puts the created items into your shop, pricing them using {{f|mall_price}}.
 
   |code=
 
   |code=
 
{{{!}} class="wikitable"
 
{{{!}} class="wikitable"
! style="width: 50%" {{!}} ASH
+
! style="width: 45%" {{!}} ASH
! style="width: 50%" {{!}} JavaScript
+
! style="width: 55%" {{!}} JavaScript
 
{{!}}- style="vertical-align: top"
 
{{!}}- style="vertical-align: top"
 
{{!}}
 
{{!}}
<syntaxhighlight lang="d" line highlight="2">
+
<syntaxhighlight lang="d" line highlight="8">
int check_price( item shopfor ) {
+
if ( stills_available() > 1 ) {
   if ( historical_age( shopfor ) > .75 )
+
   set_property( "promptAboutCrafting", 0 );
      return mall_price( shopfor );
+
  int stills_left = floor( stills_available() / 2 );
   return historical_price( shopfor );
+
  create( stills_left, $item[ Mae West ] );
 +
  print( `Created {stills_left} Mae West.`, "blue" );
 +
  set_property( "promptAboutCrafting", 1 );
 +
   put_shop(
 +
    mall_price( $item[ Mae West ] ),
 +
    0,
 +
    item_amount( $item[ Mae West ] ),
 +
    $item[ Mae West ]
 +
  );
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 
{{!}}
 
{{!}}
<syntaxhighlight lang="js" line highlight="4">
+
<syntaxhighlight lang="js" line highlight="18">
const { historicalAge, historicalPrice, mallPrice } = require("kolmafia");
+
const {
 +
  create,
 +
  itemAmount,
 +
  mallPrice,
 +
  print,
 +
  putShop,
 +
  setProperty,
 +
  stillsAvailable,
 +
} = require("kolmafia");
  
function checkPrice(shopfor) {
+
const MAE_WEST = Item.get("Mae West");
   if (historicalAge(shopfor) > .75)
+
if (stillsAvailable() > 1) {
    return mallPrice(shopfor);
+
   setProperty("promptAboutCrafting", "0");
   return historicalPrice(shopfor);
+
  let stillsLeft = Math.floor(stillsAvailable() / 2);
 +
  create(stillsLeft, MAE_WEST);
 +
  print("Created " + stillsLeft + " Mae West.", "blue");
 +
  setProperty("promptAboutCrafting", 1);
 +
   putShop(mallPrice(MAE_WEST), 0, itemAmount(MAE_WEST), MAE_WEST);
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 15:24, 31 December 2020

Function Syntax



Returns the current mall price of the given item, ignoring the first five items listed to compensate for stores with limits and min-priced sales. To prevent abuse, this will only perform an actual Mall search once per item per session; subsequent calls for the same item will return a cached value. The cache will be updated after attempts to purchase the item using the CLI or ASH buy() command (even unsuccessful ones), but not in any other conditions, including purchasing with the purchase tab.

Code Samples

Creates Mae Wests based on your stills remaining. Puts the created items into your shop, pricing them using mall_price().

ASH JavaScript
 1 if ( stills_available() > 1 ) {
 2    set_property( "promptAboutCrafting", 0 );
 3    int stills_left = floor( stills_available() / 2 );
 4    create( stills_left, $item[ Mae West ] );
 5    print( `Created {stills_left} Mae West.`, "blue" );
 6    set_property( "promptAboutCrafting", 1 );
 7    put_shop(
 8      mall_price( $item[ Mae West ] ), 
 9      0,
10      item_amount( $item[ Mae West ] ),
11      $item[ Mae West ]
12    );
13 }
 1 const {
 2   create,
 3   itemAmount,
 4   mallPrice,
 5   print,
 6   putShop,
 7   setProperty,
 8   stillsAvailable,
 9 } = require("kolmafia");
10 
11 const MAE_WEST = Item.get("Mae West");
12 if (stillsAvailable() > 1) {
13   setProperty("promptAboutCrafting", "0");
14   let stillsLeft = Math.floor(stillsAvailable() / 2);
15   create(stillsLeft, MAE_WEST);
16   print("Created " + stillsLeft + " Mae West.", "blue");
17   setProperty("promptAboutCrafting", 1);
18   putShop(mallPrice(MAE_WEST), 0, itemAmount(MAE_WEST), MAE_WEST);
19 }

See Also

historical_age() | historical_price() | mall_price() | mall_prices()