Difference between revisions of "Historical price"

From Kolmafia
Jump to navigation Jump to search
imported>Relyk
Line 1: Line 1:
{{
+
<onlyinclude>{{{{{format|Function2}}}
#vardefine:name|historical_price}}{{
+
|name=historical_price
#vardefine:return_type|int}}{{
+
|function1.return_type=int
 +
|function1.description=Returns the most recently seen mall price of an item without making a server request.
 +
|function1.param1=shop_for
 +
|function1.param1.type=item
 +
|function1.param1.description=Item to retrieve the price of
 +
|description=
 +
<p>This obeys the same restrictions as {{f|mall_price}}. Unlike {{f|mall_price}}, this function will never hit the server.</p>
 +
|code1={{CodeSample
 +
  |title=Code Samples
 +
  |description=Gives you an estimate of your total mall-worth.
 +
  |code=
 +
{{{!}} class="wikitable"
 +
! style="width: 50%" {{!}} ASH
 +
! style="width: 50%" {{!}} JavaScript
 +
{{!}}- style="vertical-align: top"
 +
{{!}}
 +
<syntaxhighlight lang="d" line highlight="8">
 +
cli_execute( "outfit save Backup" );
 +
outfit( "birthday suit" );
 +
int [ item ] inventory = get_inventory();
 +
outfit( "Backup" );
  
FunctionPage|
+
int total;
name={{#var:name}}|
+
foreach it in inventory {
 +
  total += historical_price( it ) * inventory[ it ];
 +
}
 +
string amount = to_string( total, "%,d" );
 +
print( `The estimated total mall-worth of your inventory is {amount} meat.`, "blue" );
 +
</syntaxhighlight>
 +
{{!}}
 +
<syntaxhighlight lang="js" line highlight="17">
 +
const {
 +
  cliExecute,
 +
  getInventory,
 +
  historicalPrice,
 +
  outfit,
 +
  print,
 +
  toString: formatString,
 +
} = require("kolmafia");
  
function1={{Function|
+
cliExecute("outfit save Backup");
name={{#var:name}}|
+
outfit("birthday suit");
aggregate={{#var:aggregate}}|
+
const inventory = getInventory();
return_type={{#var:return_type}}|
+
outfit("Backup");
return_also={{#var:return_also}}|
 
parameter1={{Param|item|shop_for}}|
 
p1desc={{Pspan|shop_for}} is the item to inquire on the mall price of|
 
}}|
 
  
function_description=Returns the most recently seen mall price of the given item, following the same restrictions as [[mall_price|mall_price()]]. Unlike [[mall_price|mall_price()]] this function will never hit the server. To update to a more recent price you can use [[mall_price|mall_price()]] (if you haven't called it for that item yet this session) or purchase some of {{pspan|shop_for}} in the mall.|
+
let total = 0;
 
+
for (let itemName in inventory) {
code1={{CodeSample|
+
  total += historicalPrice(Item.get(itemName)) * inventory[itemName];
title=Code Samples|
+
}
description=Gives you an estimate of your total mall-worth.|
+
// Because all JavaScript numbers are floating-point, we must format it as such
code=
+
// and manually remove everything after the dot.
<syntaxhighlight>
+
const amount = formatString(total, "%,f").split(".")[0];
cli_execute("outfit save Backup");
+
print(
cli_execute("outfit birthday suit");
+
  "The estimated total mall-worth of your inventory is " + amount + " meat.",
int[item] inventory = get_inventory();
+
  "blue"
cli_execute("outfit Backup");
+
);
int total;
+
</syntaxhighlight>
foreach it in inventory
+
{{!}}}
  total += historical_price(it) * inventory[it];
+
  |moreinfo=
string amount = to_string(total, "%,d");  
 
print("The estimated total mall-worth of your inventory is "+amount+" meat.", "blue");
 
 
 
</syntaxhighlight>|
 
moreinfo=Historical price is best used for estimates and planning. When purchasing items or putting them into your store, it is better to use mall_price.
 
}}|
 
 
 
see_also={{SeeAlso|historical_age|mall_price}}|
 
cli_equiv=The CLI command "searchmall" also returns current mall prices.|
 
 
}}
 
}}
 
+
|see_also={{SeeAlso/Mall Prices}}
[[Category:Item Management]]
+
|cli_equiv=
 +
|more_info=
 +
|special=
 +
|{{{1|}}}
 +
}}</onlyinclude>

Revision as of 14:56, 31 December 2020

Function Syntax

int historical_priceitem shop_for )

Returns the most recently seen mall price of an item without making a server request.
  • shop_for: Item to retrieve the price of

This obeys the same restrictions as mall_price(). Unlike mall_price(), this function will never hit the server.

Code Samples

Gives you an estimate of your total mall-worth.

ASH JavaScript
 1 cli_execute( "outfit save Backup" );
 2 outfit( "birthday suit" );
 3 int [ item ] inventory = get_inventory();
 4 outfit( "Backup" );
 5 
 6 int total;
 7 foreach it in inventory {
 8    total += historical_price( it ) * inventory[ it ];
 9 }
10 string amount = to_string( total, "%,d" );
11 print( `The estimated total mall-worth of your inventory is {amount} meat.`, "blue" );
 1 const {
 2   cliExecute,
 3   getInventory,
 4   historicalPrice,
 5   outfit,
 6   print,
 7   toString: formatString,
 8 } = require("kolmafia");
 9 
10 cliExecute("outfit save Backup");
11 outfit("birthday suit");
12 const inventory = getInventory();
13 outfit("Backup");
14 
15 let total = 0;
16 for (let itemName in inventory) {
17   total += historicalPrice(Item.get(itemName)) * inventory[itemName];
18 }
19 // Because all JavaScript numbers are floating-point, we must format it as such
20 // and manually remove everything after the dot.
21 const amount = formatString(total, "%,f").split(".")[0];
22 print(
23   "The estimated total mall-worth of your inventory is " + amount + " meat.",
24   "blue"
25 );

See Also

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