Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
component:crafting [2014/07/10 09:02]
vexatos
component:crafting [2015/01/14 23:40] (current)
Line 1: Line 1:
 Component: Crafting Component: Crafting
 ================= =================
-This component is provided by the [[crafting upgrade|Items#crafting-upgrade]] ​for robots.+This component ​allows a robot to craft items and is provided by the [[item:​crafting_upgrade|crafting upgrade]]. The component can be accessed via `component.crafting`.
  
-Component name: `crafting`  +When activated the robot considers the top-left area the crafting ​area and will attempt to craft any layed-out crafting recipe in that area. The requirements for a successful crafting attempt are exactly the same as if you would attempt to craft the item in a crafting table.
-Callbacks:+
  
-- `craft([countnumber]): boolean`  ​ +{{component:crafting_area.png|Crafting area}}\\ 
-  Tries to craft something from the items in the top left 3x3 area of the robot'​s inventory. If `count` is specified will only craft up that number of items. If `count` is lower than the number of items created in one crafting operation, nothing will be crafted (e.g. trying to craft one stick). Up to one stack can be crafted at a time. The result of the crafting operation will be placed into the selected slot, the first free slot after it, or dropped if the robot'​s inventory is full.+//(free slots are the crafting ​area)//
  
-Example ​use:+It is recommended (but not required) to use this upgrade in combination with an [[item:inventory_controller_upgrade|Inventory Controller Upgrade]]. It allows to read the names and types of items and therefore makes it a lot easier to find the required crafting resources. 
 + 
 +===== Functions ===== 
 +==== craft([count:​ number]): boolean ==== 
 +Crafts up to count numbers or a full stack. 
 + 
 +**count** - How many items to craft. I f omitted then the robot will craft as many items as possible. In any case the robot will never craft more than one full stack of crafting result items at once.\\ 
 +**Returns:​** `true` if at least one item was crafted, `false` otherwise.\\ 
 + 
 +Note that if you specify an amount of items to be crafted that is lower than the minimum resulting stack size (i.E. order to craft 1 stick, but minimum result stack size is 4), then nothing will be crafted, however this will still return true. 
 + 
 +If successful the crafting result will be placed in the currently selected slot, or (if occupied by something else) will be placed into the next slot containing similar items or in the next free slot. This can be one of the slots of the crafting area, which would make it impossible to craft the same item again until that area is cleared. 
 + 
 +==== Example ====
 ```lua ```lua
 local component = require("​component"​) local component = require("​component"​)
Line 15: Line 27:
 c.craft(10) -- craft up to 10 items c.craft(10) -- craft up to 10 items
 ``` ```
- 
----- 
  
 {{page>​component:​contents&​noheader&​noeditbutton&​nouser&​nofooter}} {{page>​component:​contents&​noheader&​noeditbutton&​nouser&​nofooter}}