luaminecraftcomputercraft

"bios.lua:26: [string "turbinecontrol"]:15: 'then' expected" I have no idea why this is happening


Trying to control my extremereactor turbines with a computer so i dont have to keep managing them, im quite new to lua in general so i would really like some help with this and maybe some extra advice on other things that could go wrong/im doing wrong and i am planning to have a monitor displaying stats from the turbines and be able to turn them on/off once i figure out how to do that

turbine1 = peripheral.wrap("top")
turbine2 = peripheral.wrap("right") -- i know doing this is probably wrong

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) -- line which its complaining about with "bios.lua:26: [string "turbinecontrol"]:15: 'then' expected"
    print("Turbine 1 Inductor Engaged")
    wait(5)
    print("Turbine 1 Generating" ... turbine1.getEnergyProducedLastTick())
  end

  if turbine1.getRotorSpeed() < 10000
    turbine1.setInductorEngaged(false)
    print("Turbine 1 Inductor Disengaged")
  end

  if turbine2.getRotorSpeed() >= 20000
    turbine2.setInductorEngaged(true)
    print("Turbine 2 Inductor Engaged")
    wait(5)
    print("Turbine 2 Generating" ... turbine2.getEnergyProducedLastTick())
  end

  if turbine2.getRotorSpeed() < 10000
    turbine2.setInductorEngaged(false)
    print("Turbine 2 Inductor Disengaged")
  end

end```

Solution

  • Your syntax is a little off. Firstly, you've got while true do then on line 14 when this should only be while true do, secondly, whenever you've got an if statement, eg. if turbine1.getRotorSpeed() >= 20000 you need a then to terminate the condition. Thus this should look like if turbine1.getRotorSpeed() >= 20000 then