Component/redstone in motion/zh
组件:运动红石机构
此组件代表了[Redstone in Motion(运动红石机构)]([[1]]。 注意:此组件只有在安装附属模组OpenComponents的前提下才可用! OpenComponents的内容已经被合并进Opencomputers内。
组件名:`carriage`。
回调函数:
- `getAnchored(): boolean` 获取控制器方块在车辆移动时是否应保持原位。
- `setAnchored(value: boolean): boolean` 设定控制器方块在车辆移动时是否应保持原位。返回新的值。
- `move(direction: string or number[, simulate: boolean]): boolean` 让控制器尝试移动车辆。`direction`可以为指示某方向的字符串,或sides(方向) API中的常量之一。你还可以指定是否要进行模拟运动,默认为`false`。若命令执行成功则返回`true`。 此函数不会返回移动的真正结果。 由于技术限制,移动结果将以名为`carriage_moved`的信号异步反馈给电脑。其签名为:`result[, reason: string]`,若移动失败,其中的`reason`为报错信息字符串。这是因为触发了移动的电脑可能也会进行移动,意味着电脑需要暂停运作,这必然导致电脑进入yield状态。 可用的方向字符串有:`negy`、`posy`、`negz`、`posz`、`negx`、`posx`,以及`down`、`up`、`north`、`south`、`west`、`east`。
- `simulate(direction: string or number): boolean` 类似`move(direction, true)`.
使用例:
```lua local component = require("component") local event = require("event") local sides = require("sides")
local cc = component.carriage --获取首选车辆控制器组件 cc.move("up") local _, _, result, reason, x, y, z = event.pull("carriage_moved") if not result then
if x then
print(reason)
print("Block location: " .. x .. ", " .. y .. ", " .. z)
else
print(reason)
end
end -- 使用sides表的值: cc.simulate(sides.west) ```
目录
| < 100% 15% 15% > | ||
| 组件API | 3D打印机 - 抽象总线 - 无线接入点 - 区块加载器 - 电脑 - 合成 - 数据卡 - 数据库 - 调试 - 无人机 - 驱动器 - EEPROM - 经验 - 文件系统 - 发电机 - 地质分析仪 - GPU - 全息投影仪 - 因特网 - 物品栏控制器 - 拴绳 - 微控制器 - 调制解调器 - 运动传感器 - 导航 - 网络拆分器 - 活塞 - 红石 - 运动红石机构 - 机器人 - 屏幕 - 告示牌 - 储罐控制器 - 牵引光束 - 转运器 - 隧道 - 世界传感器 | |
| ::: | 其它 | 访问组件 - 信号 |
| ::: | 模组联动 | 应用能源 |