Eat: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
Added details about boolean return value.
imported>Grotfang
No edit summary
Line 5: Line 5:
So,<br>
So,<br>
<code>
<code>
eat(3,$item[stinky hi mein]);
  eat(3,$item[stinky hi mein]);
</code>
</code>
<br>
<br>
Line 13: Line 13:
<br>
<br>
<code>
<code>
eat(3,$item[blue pixel]);
  eat(3,$item[blue pixel]);
</code>
</code>
<br>
<br>
will tell you that a blue pixel cannot be consumed and return false.
will tell you that a blue pixel cannot be consumed and return false.
This can be adapted for safer consumption by using code such as the following:
<code>
  boolean eat_hi_mein()
  {
      if( item_amount( $item[stinky hi mein] ) >= 3 )
      {
          if( ( fullness_limit() - my_fullness() ) >= 15 )
          {
              eat( 3 , $item[stinky hi mein] );
              return true;
          }
          else
              print( "You are too full to eat all of those" );
      }
      else
          print( "You have fewer than three in your inventory" );
  return false;
  }
</code>
This code uses [[item_amount()]], [[fullness_limit()]] and [[my_fullness()]] to pre-empt problems that may occur.

Revision as of 15:08, 22 February 2010

boolean eat(int quantity, item itemtype)

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.

So,

 eat(3,$item[stinky hi mein]);


will eat 3 stinky hi meins (depending on fullness) and return true.

While,

 eat(3,$item[blue pixel]);


will tell you that a blue pixel cannot be consumed and return false.

This can be adapted for safer consumption by using code such as the following:

 boolean eat_hi_mein()
 {
     if( item_amount( $item[stinky hi mein] ) >= 3 )
     {
         if( ( fullness_limit() - my_fullness() ) >= 15 )
         {
             eat( 3 , $item[stinky hi mein] );
             return true;
         }
         else
             print( "You are too full to eat all of those" );
     }
     else
         print( "You have fewer than three in your inventory" );
 return false;
 }

This code uses item_amount(), fullness_limit() and my_fullness() to pre-empt problems that may occur.