Difference between revisions of "CInventory::putOutItem"
From King Arthur's Gold Wiki
Shadlington (Talk | contribs) |
Shadlington (Talk | contribs) |
||
(One intermediate revision by the same user not shown) | |||
Line 11: | Line 11: | ||
Example from Entities/Vehicles/Scripts/CatapultLogic.as: | Example from Entities/Vehicles/Scripts/CatapultLogic.as: | ||
− | <syntaxhighlight lang="cpp" highlight="7"> | + | <syntaxhighlight lang="cpp" highlight="7, 20"> |
// fire blob from arm or if empty take one from inv | // fire blob from arm or if empty take one from inv | ||
CBlob @fireBlob = (armObject !is null) ? armObject : this.getInventory().getItem(0); | CBlob @fireBlob = (armObject !is null) ? armObject : this.getInventory().getItem(0); |
Latest revision as of 19:49, 19 August 2012
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