Historical price: Difference between revisions
Jump to navigation
Jump to search
imported>Relyk No edit summary |
Forgot to add category |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
{{ | <onlyinclude>{{{{{format|Function2}}} | ||
|name=historical_price | |||
|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" ); | |||
int total; | |||
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"); | |||
cliExecute("outfit save Backup"); | |||
outfit("birthday suit"); | |||
const inventory = getInventory(); | |||
outfit("Backup"); | |||
let total = 0; | |||
for (let itemName in inventory) { | |||
total += historicalPrice(Item.get(itemName)) * inventory[itemName]; | |||
} | |||
// Because all JavaScript numbers are floating-point, we must format it as such | |||
// and manually remove everything after the dot. | |||
const amount = formatString(total, "%,f").split(".")[0]; | |||
print( | |||
"The estimated total mall-worth of your inventory is " + amount + " meat.", | |||
"blue" | |||
); | |||
</syntaxhighlight> | |||
{{!}}} | |||
|moreinfo= | |||
print("The estimated total mall-worth of your inventory is "+amount+" meat.", "blue"); | |||
</syntaxhighlight> | |||
}} | }} | ||
|see_also={{SeeAlso/Mall Prices}} | |||
|cli_equiv= | |||
|more_info= | |||
|special= | |||
|{{{1|}}} | |||
}}</onlyinclude> | |||
[[Category:Item Management]] | [[Category:Item Management]] |
Latest revision as of 14:59, 31 December 2020
Function Syntax
int historical_price( item 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 |
---|---|
cli_execute( "outfit save Backup" );
outfit( "birthday suit" );
int [ item ] inventory = get_inventory();
outfit( "Backup" );
int total;
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" );
|
const {
cliExecute,
getInventory,
historicalPrice,
outfit,
print,
toString: formatString,
} = require("kolmafia");
cliExecute("outfit save Backup");
outfit("birthday suit");
const inventory = getInventory();
outfit("Backup");
let total = 0;
for (let itemName in inventory) {
total += historicalPrice(Item.get(itemName)) * inventory[itemName];
}
// Because all JavaScript numbers are floating-point, we must format it as such
// and manually remove everything after the dot.
const amount = formatString(total, "%,f").split(".")[0];
print(
"The estimated total mall-worth of your inventory is " + amount + " meat.",
"blue"
);
|