CInventory::putOutItem

From King Arthur's Gold Wiki
Revision as of 19:48, 19 August 2012 by Shadlington (Talk | contribs)

Jump to: navigation, search

Removes the given a CBlob from this inventory, either by CBlob reference or by name.


This method has two variants.

The first variant removes the given CBlob from this inventory, returning true if the CBlob was there to be removed, otherwise returning false.

bool putOutItem(CBlob@ blob)

Example from Entities/Vehicles/Scripts/CatapultLogic.as:

// fire blob from arm or if empty take one from inv
CBlob @fireBlob = (armObject !is null) ? armObject : this.getInventory().getItem(0);
if (fireBlob !is null)
{
  if (armObject is null) // nothing in arm?
  {
    this.getInventory().putOutItem( fireBlob ); // remove from inventory first
    this.AttachTo( fireBlob, "BOWL" ); // put it into the arm  }
  fireBlob.DetachFromAll();
 
  //fire in facing direction, with force proportional to charge
  f32 sign = this.isFacingLeft() ? 1.0f : -1.0f;
  fireBlob.AddForce( Vec2f(sign*charge, -charge/5) );
 
  //load a new item if we can
  if (this.getInventory().getItemsCount() > 0)
  {
    CBlob@ toLoad = this.getInventory().getItem(0);
    if (this.getInventory().putOutItem( toLoad ))
    {
      this.AttachTo( toLoad, "BOWL" );
    }
  }
}

The second variant looks for a CBlob with the given name in this inventory. The first one it finds with that name will be removed from the inventory and a reference to it will be returned. If it does not find a matching CBlob it will return null.

CBlob@ putOutItem(const string &blobName)

Example from Entities/Common/Scripts/BlobPlacement.as:

void PlaceBlock( CBlob@ this, CBlob @blob, Vec2f cursorPos )
{
  if (this.DetachFrom( blob ))
  {
    blob.setPosition( cursorPos );
    // find an identical one in inventory and put in hands
 
    CBlob @newBlob = this.getInventory().putOutItem( blob.getName() );    if (newBlob !is null)
    {
      // put out of inventory and into hands		
      this.PickupIntoHands( newBlob );
    }
  }
}

Object method of: CInventory