Sell: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
imported>Bale
r9555
 
imported>Gnocchi masala
m Fix obsolete syntax
 
(4 intermediate revisions by one other user not shown)
Line 22: Line 22:


code1={{CodeSample|
code1={{CodeSample|
title=Code Sample|
description=This expands upon selling to a coinmaster to show many related functions.|
description=This expands upon selling to a coinmaster to show many related functions.|
code=
code=
<syntaxhighlight>
<syntaxhighlight>
boolean sell_coinmaster(int qty, item it) {
boolean sell_coinmaster(int qty, item it) {
   coinmaster master = to_coinmaster(it.buyer);
   coinmaster master = it.buyer;
   if(master == $coinmaster[none]) {
   if(master == $coinmaster[none]) {
       print("You do not need a coinmaster to purchase that", "red");
       print("No coinmaster will purchase that", "red");
       return false;
       return false;
   }
   }
Line 37: Line 38:
   int coins = master.available_tokens;
   int coins = master.available_tokens;
   int price = sell_price(master, it);
   int price = sell_price(master, it);
   print("Selling to "+master+" for "+price+" "+coins);
   print("Selling "+it+" to "+master+" for "+price+" "+coins+(qty > 1? " each.": "."));
   return sell(master, qty, it);
   return sell(master, qty, it);
}
}
Line 44: Line 45:


see_also={{SeeAlso|buy|sell_price}}|
see_also={{SeeAlso|buy|sell_price}}|
cli_equiv=The CLI commands "buy" and "acquire" work similarly.|
}}
}}


[[Category:Item Management]]
[[Category:Item Management]]

Latest revision as of 05:54, 18 March 2012

Function Syntax

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

  • master is the coinmaster to purchase from
  • qty is the number to purchase
  • it is the item to purchase

Attempts to purchase qty amount of item it from master. If qty is less than 1, the function will return true without purchasing anything. Otherwise it returns true if the purchase succeeded and false if it did not.

Code Sample

This expands upon selling to a coinmaster to show many related functions.

boolean sell_coinmaster(int qty, item it) {
   coinmaster master = it.buyer;
   if(master == $coinmaster[none]) {
      print("No coinmaster will purchase that", "red");
      return false;
   }
   if(!is_accessible(master)) {
      print(inaccessible_reason(master), "red");
      return false;
   }
   int coins = master.available_tokens;
   int price = sell_price(master, it);
   print("Selling "+it+" to "+master+" for "+price+" "+coins+(qty > 1? " each.": "."));
   return sell(master, qty, it);
}

See Also

buy() | sell_price()