This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
NillzK's profile picture

End Fuction Error [lua]

Started by NillzK, 18 February 2013 - 02:24 AM
NillzK #1
Posted 18 February 2013 - 03:24 AM
Title: End Fuction Error [lua]

Hello, I'm trying to get my Industrialcraft Reactor/Breeder to Work with Computercraft.

Errortype: every function returns an end-error. I suspect that I use the "function" incorrectly since I'm new to computercraft (could do this with redpower).

Thanks for your help.

My Code:
Spoiler– Automatic Nuclear-Reactor (100 EU/t per Reactor) with Breeder (5 EU/t) v 0.1

– Bundledcable (Back)
– White = Input Nuclear Control < 500 Reaktor One
– Orange = Input Nuclear Control < 500 Reaktor Two
– Magenta = Input Nuclear Control < 8000 Breeder One
– Green = Input MFSU = full
– Black = Input MFE = empty (no energy to power "Nuclear Control")

– Bundledcable (Bottom)
– White = Output Reactor One = On
– Orange = Output Reactor Two = On
– Magenta = Output Breeder One = On
– Black = Output Timer autoRefill = Off (unused atm)

– Top (single Redwire Signal)
– Mastercontrol = Input = Enable Control Program (Reactors run if conditons are met)


local Reactorcontrol
local ReactorOne
local ReactorTwo
local BreederOne
local ErrorCooling
local ErrorStorage
local ErrorRefillUraniumCell
local ErrorCoalDust
local ErrorIsotopCells
local Reactorcontrol

function Reactorcontrol()
while rs.testInput("top") == true
do
ReactorOne()
ReactorTwo()
BreederOne()
ErrorCooling()
ErrorStorage()
ErrorRefillUraniumCell()
ErrorCoalDust()
ErrorIsotopCells()
sleep(2)
end
else print("Control Disabled")
sleep(5)
end

function ReactorOne()

if rs.testBundledInput("back" , (colors.white)) == false
and rs.testBundledInput("back" , (colors.black)) == false
and rs.testBundledInput("back" , (colors.green)) == false
then print("Reactor One online") rs.setBundledOutput("bottom" , (colors.white))
end
else print("Reactor One offline")
end


function ReactorTwo()
if rs.testBundledInput("back" , (colors.orange)) == false
and rs.testBundledInput("back" , (colors.black)) == false
and rs.testBundledInput("back" , (colors.green)) == false
then print("Reactor Two online")
rs.setBundledOutput("bottom" , (colors.orange))
end
else print("Reactor Two offline")
end

function BreederOne()
if rs.testBundledInput("back" , colors.magenta) == false
and rs.testBundledInput("back" , colors.black) == false
then
rs.setBundledOutput("bottom" , (colors.magenta))
print("Breeder One online")
end
else print("Breeder One offline")
end

function ErrorCooling()
if rs.testBundledInput("back" , colors.white) == true
or rs.testBundledInput("back" , colors.orange) == true
or rs.testBundledInput("back" , colors.magenta) == true
then print("Cooling Error")
end
end

function ErrorStorage()
if rs.testBundledInput("bottom" , colors.green) == true
then print("Storage Overflow")
end
end


function ErrorRefillUraniumCell()
if rs.testBundledInput("bottom" , colors.yellow) == false
then print("Refill Uranium Cells")
end
end

function ErrorCoalDust()
if rs.testBundledInput("bottom" , colors.red) == false
then print("Refill Coal Dust")
end
end

function ErrorIsotopCells()
if rs.testBundledInput("bottom" , colors.blue) == false
then print("Refill Isotop Cells")
end
end
ikke009 #2
Posted 18 February 2013 - 05:21 AM
it errors because you use while and if sentences wrong.
The correct use is
while *statement here* do
end

and for if
if *statement here* then
end
ChunLing #3
Posted 19 February 2013 - 01:36 AM
To expand on that, the use of elseif and else in an if statement takes place before rather than after the end. So:
if rs.testBundledInput("back" , (colors.white)) == false
and rs.testBundledInput("back" , (colors.black)) == false
and rs.testBundledInput("back" , (colors.green)) == false
then print("Reactor One online") rs.setBundledOutput("bottom" , (colors.white))
-- end is not needed here
else print("Reactor One offline")
end
A note, you don't need a comparison operation in every single conditional. Something like "booleanReturnFunction() == true" can be replaced with "booleanReturnFunction()", while "booleanReturnFunction() == false" can be replaced with "not booleanReturnFunction()", and you eliminate the unnecessary comparison operation making the code slightly faster (there also are potential problems that arise with explicit comparisons sometimes breaking otherwise good code). Thus:
if not rs.testBundledInput("back" , (colors.white))
and not rs.testBundledInput("back" , (colors.black))
and not rs.testBundledInput("back" , (colors.green))
then print("Reactor One online") rs.setBundledOutput("bottom" , (colors.white))
else print("Reactor One offline")
end
Or
if rs.testBundledInput("back" , (colors.white))
or rs.testBundledInput("back" , (colors.black))
or rs.testBundledInput("back" , (colors.green))
then print("Reactor One offline")
else print("Reactor One online") rs.setBundledOutput("bottom" , (colors.white))
end
Edited on 19 February 2013 - 12:39 AM