"bios.lua:26: [string "turbinecontrol"]:15: 'then' expected" 我不知道为什么会发生这种情况

我正在尝试使用计算机控制我的极限反应堆涡轮机,以便我不必一直管理它们。我对 Lua 一般性不太熟悉,所以我真的希望能得到一些帮助,或者关于其他可能出错的事情/我做错的事情的额外建议。我计划有一个显示涡轮机统计信息并能够打开/关闭它们的监视器,一旦我弄清楚如何做到这一点

turbine1 = peripheral.wrap("top")
turbine2 = peripheral.wrap("right") -- 我知道这样做可能是错误的

turbine1.setActive(true)
turbine2.setActive(true)

turbine1.setVentOverflow(true)
turbine2.setVentOverflow(true)

turbine1.setFluidFlowRateMax(2000)
turbine2.setFluidFlowRateMax(2000)

while true do then
  if turbine1.getRotorSpeed() >= 20000
    turbine1.setInductorEngaged(true) -- 这是它抱怨的那一行 "bios.lua:26: [string "turbinecontrol"]:15: 'then' expected"
    print("涡轮机 1 醒目")
    wait(5)
    print("涡轮机 1 正在发电" ... turbine1.getEnergyProducedLastTick())
  end

  if turbine1.getRotorSpeed() < 10000
    turbine1.setInductorEngaged(false)
    print("涡轮机 1 触发器脱离")
  end

  if turbine2.getRotorSpeed() >= 20000
    turbine2.setInductorEngaged(true)
    print("涡轮机 2 醒目")
    wait(5)
    print("涡轮机 2 正在发电" ... turbine2.getEnergyProducedLastTick())
  end

  if turbine2.getRotorSpeed() < 10000
    turbine2.setInductorEngaged(false)
    print("涡轮机 2 触发器脱离")
  end

end```
点赞
用户7170955
用户7170955

你的语法有些错误。 首先,在第14行,你写的应该是 while true do 而不是 while true do then。其次,每当你使用 if 语句,比如 if turbine1.getRotorSpeed() >= 20000,你需要有一个 then 来终止条件。因此,应该写成 if turbine1.getRotorSpeed() >= 20000 then

2019-05-29 01:23:44