**This is an old revision of the document!**

组件:合成

此组件由合成升级提供,让机器人得以合成物品。此组件可通过component.crafting访问。

当组件启用时,机器人会将物品栏的左上角当作合成区域,并尝试在此区域中通过摆放的材料合成物品。若要成功合成,材料的摆放需要与使用合成台合成时完全一致。

Crafting area
(图中的空余槽位即为合成区域)

推荐(但不必须)将此升级与物品栏控制器升级配合使用。这样做可以读取物品的名称和类型,以便于找到所需的合成资源。

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

snippet.lua
local component = require("component")
local c = component.crafting -- get primary crafting component
c.craft(10) -- craft up to 10 items

目录