Eat: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
Added details about boolean return value.
 
(9 intermediate revisions by 5 users not shown)
Line 1: Line 1:
'''[[boolean]] eat(int quantity, item itemtype)'''
<onlyinclude>{{{{{format|Function2}}}
|name=eat
|function1.return_type=boolean
|function1.description=Attempts to eat the {{pspan|food}} item(s).
|function1.param1=food
|function1.param1.type=item
|function1.param1.description=Item to eat
|function1.param2=qty
|function1.param2.type=int
|function1.param2.description=Amount to eat
|function1.param2.optional=yes
|function1.param2.default=1
|function2.return_type=boolean
|function2.description=Attempts to eat {{pspan|qty}} of {{pspan|item}}.
|function2.param1=qty
|function2.param1.type=int
|function2.param1.description=Amount to eat
|function2.param2=food
|function2.param2.type=item
|function2.param2.description=Item to eat
|description=<p>Attempts to eat {{pspan|qty}} amount of the {{pspan|food}} item. Returns <code>true</code> for edible items and <code>false</code> for items that are not. (The return value does not reflect whether or not the items were actually consumed.)</p>


Will attempt to eat the number of food specified. The return value only tells you whether the item can be eaten, not if you have enough room for it.
<p>You can also "eat" food helper items (e.g. {{kolwiki|Ol' Scratch's salad fork}}) to queue them before eating the actual food item. Food helpers can be identified with {{f|item_type}}, which returns <code>"food helper"</code> for such items. To cancel all queued food helpers, call {{f|clear_food_helper}}.</p>


So,<br>
<p>If you can use {{kolwiki|milk of magnesium}} but haven't used one yet, this command will show a warning dialog.</p>
<code>
|code1={{CodeSample|
eat(3,$item[stinky hi mein]);
  title=Code Sample|
</code>
  description=Eats as many olive lo meins as possible.|
<br>
  code={{{!}} class="wikitable" style="margin: auto"
will eat 3 stinky hi meins (depending on fullness) and return true.
! ASH !! JavaScript
{{!}}-
{{!}}
<syntaxhighlight lang="d" line highlight="2">
int amount = (fullness_limit() - my_fullness()) / 3;
eat(amount, $item[olive lo mein]);
</syntaxhighlight>
{{!}}
<syntaxhighlight lang="javascript" line highlight="4">
const { eat, fullnessLimit, myFullness } = require("kolmafia");


While,
const amount = Math.floor((fullnessLimit() - myFullness()) / 4);
<br>
drink(amount, Item.get('olive lo mein'));
<code>
</syntaxhighlight>
eat(3,$item[blue pixel]);
{{!}}}
</code>
}}
<br>
|cli_equiv=The CLI command <code>eat</code> works similarly.
will tell you that a blue pixel cannot be consumed and return false.
|see_also={{SeeAlso/Food Management}}
}}
</onlyinclude>
[[Category:Item Management]]

Latest revision as of 14:32, 13 July 2021

Function Syntax

boolean eatitem food, int? qty = 1 )

Attempts to eat the food item(s).
  • food: Item to eat
  • qty: Amount to eat

boolean eatint qty, item food )

Attempts to eat qty of item.
  • qty: Amount to eat
  • food: Item to eat

Attempts to eat qty amount of the food item. Returns true for edible items and false for items that are not. (The return value does not reflect whether or not the items were actually consumed.)

You can also "eat" food helper items (e.g. Ol' Scratch's salad fork) to queue them before eating the actual food item. Food helpers can be identified with item_type(), which returns "food helper" for such items. To cancel all queued food helpers, call clear_food_helper().

If you can use milk of magnesium but haven't used one yet, this command will show a warning dialog.

Code Sample

Eats as many olive lo meins as possible.

ASH JavaScript
int amount = (fullness_limit() - my_fullness()) / 3;
eat(amount, $item[olive lo mein]);
const { eat, fullnessLimit, myFullness } = require("kolmafia");

const amount = Math.floor((fullnessLimit() - myFullness()) / 4);
drink(amount, Item.get('olive lo mein'));

CLI Equivalent

The CLI command eat works similarly.

See Also

can_eat() | clear_food_helper() | eat() | eatsilent()