Component/generator/zh: Difference between revisions

From OpenComputers: Rebooted
Jump to navigation Jump to search
imported>OCDoc Import
Imported from legacy OpenComputers documentation at ocdoc.cil.li
 
Clean up Markdown artifacts from DokuWiki migration
 
Line 3: Line 3:
此组件由[[Item/generator upgrade/zh|发电机升级]]提供给机器人使用。发电机的内部有物品栏,可以存储一个燃料物品堆。此API可用于与此物品栏交互。
此组件由[[Item/generator upgrade/zh|发电机升级]]提供给机器人使用。发电机的内部有物品栏,可以存储一个燃料物品堆。此API可用于与此物品栏交互。


组件名:`generator`。
组件名:<code>generator</code>。


回调函数:
回调函数:


* `count(): number`
* <code>count(): number</code>


<pre>当前发电机内部的燃料物品数。
<pre>当前发电机内部的燃料物品数。
</pre>
</pre>


* `insert([count: number]): boolean[, string]`
* <code>insert([count: number]): boolean[, string]</code>


<pre>从当前选定的物品栏槽位中转移燃料物品到发电机的物品栏,至多指定数量个。若至少有一个物品被移动到发电机的物品栏中则返回`true`,其他情况下返回`false`以及一条报错信息。 
<pre>从当前选定的物品栏槽位中转移燃料物品到发电机的物品栏,至多指定数量个。若至少有一个物品被移动到发电机的物品栏中则返回true,其他情况下返回false以及一条报错信息。
</pre>
</pre>
可能的报错信息有: `selected slot does not contain fuel`(所选槽位没有燃料)代表着选中的槽位中没有可燃烧的物品。 `different fuel type already queued`(队列中已有不同种燃料)代表发电机中已经有另一种燃料物品存在 `queue is full`(队列已满)代表着发电机中已有64个此种物品
可能的报错信息有: <code>selected slot does not contain fuel</code>(所选槽位没有燃料)代表着选中的槽位中没有可燃烧的物品。 <code>different fuel type already queued</code>(队列中已有不同种燃料)代表发电机中已经有另一种燃料物品存在 <code>queue is full</code>(队列已满)代表着发电机中已有64个此种物品
* `remove([count: number]): boolean`
* <code>remove([count: number]): boolean</code>


<pre>从发电机物品栏中移除燃料物品,并放置到当前选定的物品栏槽位或其后首个空闲槽位中,至多指定数量个。若至少有一个物品被从发电机的物品栏中移除则返回`true`,其他情况下返回`false`。
<pre>从发电机物品栏中移除燃料物品,并放置到当前选定的物品栏槽位或其后首个空闲槽位中,至多指定数量个。若至少有一个物品被从发电机的物品栏中移除则返回true,其他情况下返回false。
</pre>
</pre>
使用例: ```lua local component = require("component") --假设发电机刚被安装到机器人上,且选定槽位有一组煤炭: local g = component.generator --获取首选发电机组件 print(g.count()) -- 0 g.insert(1) -- true print(g.count()) --返回0,因为物品立刻被消耗,发电机现在开始运行 g.insert(5) print(g.count()) -- 5 g.remove() --从发电机中移除所有物品 print(g.count()) -- 0 g.insert() --将所有物品添加到发电机中 print(g.count()) -- 63(去掉一开始消耗掉的一个) ```
使用例: <syntaxhighlight lang="lua">
local component = require("component") --假设发电机刚被安装到机器人上,且选定槽位有一组煤炭: local g = component.generator --获取首选发电机组件 print(g.count()) -- 0 g.insert(1) -- true print(g.count()) --返回0,因为物品立刻被消耗,发电机现在开始运行 g.insert(5) print(g.count()) -- 5 g.remove() --从发电机中移除所有物品 print(g.count()) -- 0 g.insert() --将所有物品添加到发电机中 print(g.count()) -- 63(去掉一开始消耗掉的一个)
</syntaxhighlight>


== 目录 ==
== 目录 ==


{{:Component/contents/zh}}
{{:Component/contents/zh}}

Latest revision as of 20:27, 24 August 2026

组件:发电机

此组件由发电机升级提供给机器人使用。发电机的内部有物品栏,可以存储一个燃料物品堆。此API可用于与此物品栏交互。

组件名:generator。

回调函数:

  • count(): number
当前发电机内部的燃料物品数。
  • insert([count: number]): boolean[, string]
从当前选定的物品栏槽位中转移燃料物品到发电机的物品栏,至多指定数量个。若至少有一个物品被移动到发电机的物品栏中则返回true,其他情况下返回false以及一条报错信息。

可能的报错信息有: selected slot does not contain fuel(所选槽位没有燃料)代表着选中的槽位中没有可燃烧的物品。 different fuel type already queued(队列中已有不同种燃料)代表发电机中已经有另一种燃料物品存在 queue is full(队列已满)代表着发电机中已有64个此种物品

  • remove([count: number]): boolean
从发电机物品栏中移除燃料物品,并放置到当前选定的物品栏槽位或其后首个空闲槽位中,至多指定数量个。若至少有一个物品被从发电机的物品栏中移除则返回true,其他情况下返回false。

使用例:

local component = require("component") --假设发电机刚被安装到机器人上,且选定槽位有一组煤炭: local g = component.generator --获取首选发电机组件 print(g.count()) -- 0 g.insert(1) -- true print(g.count()) --返回0,因为物品立刻被消耗,发电机现在开始运行 g.insert(5) print(g.count()) -- 5 g.remove() --从发电机中移除所有物品 print(g.count()) -- 0 g.insert() --将所有物品添加到发电机中 print(g.count()) -- 63(去掉一开始消耗掉的一个)

目录

< 100% 15% 15% >
组件API 3D打印机 - 抽象总线 - 无线接入点 - 区块加载器 - 电脑 - 合成 - 数据卡 - 数据库 - 调试 - 无人机 - 驱动器 - EEPROM - 经验 - 文件系统 - 发电机 - 地质分析仪 - GPU - 全息投影仪 - 因特网 - 物品栏控制器 - 拴绳 - 微控制器 - 调制解调器 - 运动传感器 - 导航 - 网络拆分器 - 活塞 - 红石 - 运动红石机构 - 机器人 - 屏幕 - 告示牌 - 储罐控制器 - 牵引光束 - 转运器 - 隧道 - 世界传感器
::: 其它 访问组件 - 信号
::: 模组联动 应用能源