组件:运动红石机构

此组件代表了Redstone in Motion(运动红石机构)模组的车辆控制器方块。
注意:此组件只有在安装附属模组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状态。
    可用的方向字符串有:negyposynegzposznegxposx,以及downupnorthsouthwesteast

  • simulate(direction: string or number): boolean
    类似move(direction, true).

使用例:

snippet.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)

目录