Cafu Engine
ComponentInventoryT Class Reference

This component keeps an inventory count for an arbitrary set of items. More...

Inheritance diagram for ComponentInventoryT:

Public Member Functions

any get (string item_name)
 Returns the inventory count for the specified item. More...
 
 set (string item_name, number item_count)
 Sets the inventory count for the specified item. More...
 
 Add (string item_name, number amount)
 Changes the inventory count of the specified item by the given amount. More...
 
 CheckMax (string item_name)
 Checks if the inventory count of the specified item is at the item's maximum. More...
 
- Public Member Functions inherited from ComponentBaseT
any get (string var_name)
 Returns the value of an attribute (a member variable) of this class. More...
 
 set (string var_name, any new_value)
 Sets an attribute (a member variable) of this class to a new value. More...
 
string GetExtraMessage (string var_name)
 Returns the result of VarBaseT::GetExtraMessage() for the given member variable. More...
 
 interpolate (string var_name, number start_value, number end_value, number time)
 Schedules a value for interpolation between a start and end value over a given period of time. More...
 
EntityT GetEntity ()
 Returns the entity that this component is a part of (or nil if the component is currently "stand-alone", not a part of any entity). More...
 
 InitClientApprox (string VarName)
 Registers the given attribute (a member variable) of this class for interpolation over client frames in order to bridge the larger intervals between server frames. More...
 
 OnInit ()
 This method is called for each component of each entity as the last step of initializing a newly loaded map. More...
 
 OnClientFrame (number t)
 This method is called for each component of each entity before the client renders the next frame. More...
 

Detailed Description

This component keeps an inventory count for an arbitrary set of items.

An item can be anything that can be described with a string. Contrary to other components, an inventory is flexible regarding the "kind" and number of items that it keeps the counts for. However, it is focused on being used by script code; it is not possible to inspect and edit the contained items in the Map Editor at this time.

Note that the variables of this class (also referred to as "Public Attributes" or "Member Data") must be used with the get() and set() methods at this time – see get() and set() for details.

If you would like to create a new component of this type explicitly (those defined in the CaWE Map Editor are instantiated automatically), use WorldT::new():

local comp = world:new("ComponentInventoryT")
Implementing C++ Class:
cf::GameSys::ComponentInventoryT

Member Function Documentation

Add ( string  item_name,
number  amount 
)

Changes the inventory count of the specified item by the given amount.

The amount can be positive to increase the inventory count or negative to decrease it. The resulting inventory count is clamped to the maximum for the item, if such a maximum is set. It is also clamped to 0 (for negative amounts). The function returns true if the resulting inventory count was clamped on either boundary, or false if no clamping was applied.

Parameters
item_nameThe name of the item whose count is to be changed.
amountThe amount by which the inventory count is changed.
CheckMax ( string  item_name)

Checks if the inventory count of the specified item is at the item's maximum.

Returns true if the inventory count of the specified item is equal to (or even exceeds) its defined maximum. Returns false if no maximum is defined or if the inventory count is below the defined value.

Parameters
item_nameThe name of the item to check the count for.
any get ( string  item_name)

Returns the inventory count for the specified item.

Parameters
item_nameThe name of the item to return the count for.
set ( string  item_name,
number  item_count 
)

Sets the inventory count for the specified item.

Parameters
item_nameThe name of the item to set the count for.
item_countThe new inventory count to set.