Difference between revisions of "Historical age"

From Kolmafia
Jump to navigation Jump to search
imported>Bale
(created page)
 
m
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{
+
<onlyinclude>{{{{{format|Function2}}}
#vardefine:name|historical_age}}{{
+
|name=historical_age
#vardefine:return_type|float}}{{
+
|function1.return_type=float
 
+
|function1.description=Returns the age of the price returned by {{f|historical_age}} in days.
FunctionPage|
+
|function1.param1=shop_for
name={{#var:name}}|
+
|function1.param1.type=item
function_category=Item Management|
+
|function1.param1.description=Item to check for
 
+
|description=The return value is in days. For example, a return value of 0.5 means that the price is 12 hours old.
function1={{Function|
+
|code1={{CodeSample
name={{#var:name}}|
+
  |title=Code Samples
aggregate={{#var:aggregate}}|
+
  |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.
return_type={{#var:return_type}}|
+
  |code=
return_also={{#var:return_also}}|
+
{{{!}} class="wikitable"
parameter1={{Param|item|shop_for}}|
+
! style="width: 50%" {{!}} ASH
p1desc={{Pspan|shop_for}} for which to check the price's age|
+
! style="width: 50%" {{!}} JavaScript
}}|
+
{{!}}- style="vertical-align: top"
 +
{{!}}
 +
<syntaxhighlight lang="d" line highlight="2">
 +
int check_price( item shopfor ) {
 +
  if ( historical_age( shopfor ) > .75 )
 +
      return mall_price( shopfor );
 +
  return historical_price( shopfor );
 +
}
 +
</syntaxhighlight>
 +
{{!}}
 +
<syntaxhighlight lang="js" line highlight="4">
 +
const { historicalAge, historicalPrice, mallPrice } = require("kolmafia");
  
function_description=Returns the age of the price that [[historical_price|historical_price()]] will return. The return value is in days, so a returned value of 1.25 means that the price is 1 day and 6 hours old.|
+
function checkPrice(shopfor) {
 
+
  if (historicalAge(shopfor) > .75)
code1={{CodeSample|
+
    return mallPrice(shopfor);
title=Code Samples|
+
  return historicalPrice(shopfor);
description=Returns a price no more than 18 hours old by checking mall_price() if the historical_price() is older than that.|
 
code=
 
<syntaxhighlight>
 
int check_price(item shopfor) {
 
  if(historical_age(shopfor) > .75)
 
      return mall_price(shopfor);
 
  return historical_price(shopfor);
 
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
}}|
+
{{!}}}
 
+
  |moreinfo=
see_also={{SeeAlso|historical_price|mall_price}}|
 
 
}}
 
}}
 +
|see_also={{SeeAlso/Mall Prices}}
 +
|cli_equiv=
 +
|more_info=
 +
|special=
 +
|{{{1|}}}
 +
}}</onlyinclude>
 +
[[Category:Item Management]]

Latest revision as of 15:06, 31 December 2020

Function Syntax

float historical_ageitem shop_for )

Returns the age of the price returned by historical_age() in days.
  • shop_for: Item to check for

The return value is in days. For example, a return value of 0.5 means that the price is 12 hours old.

Code Samples

This function returns a price no more than 18 hours old by checking mall_price() if historical_price() is older than that.

ASH JavaScript
1 int check_price( item shopfor ) {
2    if ( historical_age( shopfor ) > .75 )
3       return mall_price( shopfor );
4    return historical_price( shopfor );
5 }
1 const { historicalAge, historicalPrice, mallPrice } = require("kolmafia");
2 
3 function checkPrice(shopfor) {
4   if (historicalAge(shopfor) > .75)
5     return mallPrice(shopfor);
6   return historicalPrice(shopfor);
7 }

See Also

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