Buy: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
imported>Bale
less than 1 info.
imported>Bale
r9555 added coinmaster functionality
Line 16: Line 16:


function2={{Function|
function2={{Function|
name={{#var:name}}|
aggregate={{#var:aggregate}}|
return_type=boolean|
return_also={{#var:return_also}}|
parameter1={{Param|coinmaster|master}}|
parameter2={{Param|int|qty}}|
parameter3={{Param|item|it}}|
}}|
function3={{Function|
name={{#var:name}}|
name={{#var:name}}|
aggregate={{#var:aggregate}}|
aggregate={{#var:aggregate}}|
Line 26: Line 36:
p2desc={{pspan|it}} is the item to purchase|
p2desc={{pspan|it}} is the item to purchase|
p3desc={{pspan|price}} is the (optional) maximum price to spend per item|
p3desc={{pspan|price}} is the (optional) maximum price to spend per item|
p4desc={{pspan|master}} is the coinmaster to purchase from|
}}|
}}|


function_description=Attempts to purchase {{pspan|qty}} amount of item {{pspan|it}}. If {{pspan|qty}} is less than 1, the function will return true without purchasing anything. If the optional maximum {{pspan|price}} is specified, it returns the integer amount of items purchased; otherwise it returns true if the purchase succeeded and false if it did not. Without the optional {{pspan|price}} parameter, first preference is given to NPC stores when attempting purchases, after which it will attempt to use the mall.|
function_description=Attempts to purchase {{pspan|qty}} amount of item {{pspan|it}}. If {{pspan|qty}} is less than 1, the function will return true without purchasing anything. If the optional maximum {{pspan|price}} is specified, it returns the integer amount of items purchased; otherwise it returns true if the purchase succeeded and false if it did not. Without the optional {{pspan|price}} parameter, first preference is given to NPC stores when attempting purchases, after which it will attempt to use the mall.</p>
 
<p>If a {{pspan|coinmaster}} is listed, it will attempt to purchase from the coinmaster using the correct alternate currency. Otherwise it will be purchased from an NPC store or mall using meat.|


code1={{CodeSample|
code1={{CodeSample|
Line 36: Line 49:
<syntaxhighlight>
<syntaxhighlight>
buy(1 , $item[broken skull]);
buy(1 , $item[broken skull]);
</syntaxhighlight>}}|
</syntaxhighlight>}}
 
{{CodeSample|
description=This expands upon purchasing from a coinmaster to show many related functions.|
code=
<syntaxhighlight>
boolean buy_coinmaster(int qty, item it) {
  coinmaster master = to_coinmaster(it.seller);
  if(master == $coinmaster[none]) {
      print("You do not need a coinmaster to purchase that", "red");
      return false;
  }
  if(!is_accessible(master)) {
      print(inaccessible_reason(master), "red");
      return false;
  }
  int coins = master.available_tokens;
  int price = buy_price(master, it);
  if(price > coins) {
      print("You only have "+coins+" "+master.token+", but it costs "+price+" "+master.token, "red");
      return false;
  }
  return buy(master, qty, it);
}
</syntaxhighlight>
}}|


see_also={{SeeAlso|use}}|
see_also={{SeeAlso|use}}|

Revision as of 23:38, 18 July 2011

Function Syntax

boolean buy(int qty ,item it )

boolean buy(coinmaster master ,int qty ,item it )

int buy(int qty ,item it ,int price )

  • qty is the number to purchase
  • it is the item to purchase
  • price is the (optional) maximum price to spend per item
  • master is the coinmaster to purchase from

Attempts to purchase qty amount of item it. If qty is less than 1, the function will return true without purchasing anything. If the optional maximum price is specified, it returns the integer amount of items purchased; otherwise it returns true if the purchase succeeded and false if it did not. Without the optional price parameter, first preference is given to NPC stores when attempting purchases, after which it will attempt to use the mall.

If a coinmaster is listed, it will attempt to purchase from the coinmaster using the correct alternate currency. Otherwise it will be purchased from an NPC store or mall using meat.

Code Sample

Buy a broken skull.

buy(1 , $item[broken skull]);


This expands upon purchasing from a coinmaster to show many related functions.

boolean buy_coinmaster(int qty, item it) {
   coinmaster master = to_coinmaster(it.seller);
   if(master == $coinmaster[none]) {
      print("You do not need a coinmaster to purchase that", "red");
      return false;
   }
   if(!is_accessible(master)) {
      print(inaccessible_reason(master), "red");
      return false;
   }
   int coins = master.available_tokens;
   int price = buy_price(master, it);
   if(price > coins) {
      print("You only have "+coins+" "+master.token+", but it costs "+price+" "+master.token, "red");
      return false;
   }
   return buy(master, qty, it);
}

CLI Equivalent

The CLI commands "buy" and "acquire" work similarly.

See Also

use()