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

[LUA][Error] Bad Argument, Double Expected got nil

Started by PoisonMondo, 13 October 2012 - 07:04 AM
PoisonMondo #1
Posted 13 October 2012 - 09:04 AM
I have looked around and found this generally means there is something named incorrectly, but i cant seem to work it out. One minute it was working the next not. i went and used the same code when it was working but still gave the same error.

-- Coded by PoisonMondo & Help from community
-- Reactor control: Turn on Reactor
rout = colors.subtract(rout,colors.red)
rs.setBundledOutput("back",rout)
-- Make sure input is intialised
rin=rs.getBundledInput("bottom")
mon = peripheral.wrap('top')
mon.setTextScale(1)
i = 1
repeat
mon.clear()
mon.setCursorPos(3,1)
mon.write("========POISONSYS REACTOR=========")
mon.setCursorPos(3,2)
mon.write("=======CONTROL SYSTEM V1.0========")
if rs.testBundledInput("bottom", colors.red) then
mon.setCursorPos(1,4)
mon.write("Reactor is  : OFFLINE")
else
mon.setCursorPos(1,4)
mon.write("Reactor is  : ONLINE")
end
if rs.testBundledInput("bottom", colors.black) then
mon.setCursorPos(1,6)
mon.write("Wtr_cooling is  : ONLINE")
else
mon.setCursorPos(1,6)
mon.write("Wtr_cooling is  : OFFLINE")
end
if rs.testBundledInput("bottom", colors.green) then
mon.setCursorPos(1,8)
mon.write("Ice_cooling is  : ONLINE")
else
mon.setCursorPos(1,8)
mon.write("Ice_cooling is  : OFFLINE")
end
if rs.testBundledInput("bottom", colors.orange) then
mon.setCursorPos(1,10)
mon.write("Reactor Meltdown: True")
rout = colors.combine(rout,colors.red)
rs.setBundledOutput("back",rout)
else
mon.setCursorPos(1,10)
mon.write("Reactor Meltdown: False")
rout = colors.subtract(rout,colors.red)
rs.setBundledOutput("back",rout)
end
i = i + 1
sleep(3)
until i > 13243
Luanub #2
Posted 13 October 2012 - 11:04 AM
Can you put the whole error message? It should include the line number that is erroring.

Edit: Nevermind Don't need it.

The issue is on line 3

rout = colors.subtract(rout,colors.red)

Since this is the start of the code rout is not yet defined and you start out by subtracting from it, which if anything is going to make it a negative number.

I'm assuming you want to start out with red on? If so here's how you should probably do it.

local rout = 0 -- declare it first, this makes it a number and also ensures that no other color is turned on. Also notice I made it a local. You should start using local vars whenever you can(which is close to all the time).
rout = colors.combine(rout,colors.red) --use combine not subtract

Another tip instead of using a loop plus using a var to manually keep track of the iterations just use a numerical for loop. It will keep track for you.

for x=1, 13243 do
--will run any code here 13243 times
end

Here's a cleaned up version:
Spoiler

-- Coded by PoisonMondo & Help from community
-- Reactor control: Turn on Reactor
local rout = 0
rout = colors.combine(rout, colors.red)
rs.setBundledOutput("back",rout)
-- Make sure input is intialised
local mon = peripheral.wrap('top')
mon.setTextScale(1)
for x=1, 13242 do
mon.clear()
mon.setCursorPos(3,1)
mon.write("========POISONSYS REACTOR=========")
mon.setCursorPos(3,2)
mon.write("=======CONTROL SYSTEM V1.0========")
if rs.testBundledInput("bottom", colors.red) then
mon.setCursorPos(1,4)
mon.write("Reactor is  : OFFLINE")
else
mon.setCursorPos(1,4)
mon.write("Reactor is  : ONLINE")
end
if rs.testBundledInput("bottom", colors.black) then
mon.setCursorPos(1,6)
mon.write("Wtr_cooling is  : ONLINE")
else
mon.setCursorPos(1,6)
mon.write("Wtr_cooling is  : OFFLINE")
end
if rs.testBundledInput("bottom", colors.green) then
mon.setCursorPos(1,8)
mon.write("Ice_cooling is  : ONLINE")
else
mon.setCursorPos(1,8)
mon.write("Ice_cooling is  : OFFLINE")
end
if rs.testBundledInput("bottom", colors.orange) then
mon.setCursorPos(1,10)
mon.write("Reactor Meltdown: True")
rout = colors.combine(rout,colors.red)
rs.setBundledOutput("back",rout)
else
mon.setCursorPos(1,10)
mon.write("Reactor Meltdown: False")
rout = colors.subtract(rout,colors.red)
rs.setBundledOutput("back",rout)
end
sleep(3)
end
Edited on 13 October 2012 - 09:22 AM
PoisonMondo #3
Posted 13 October 2012 - 11:32 AM
thankyou so much