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

Attempt to call nil

Started by thepowdertoy, 07 June 2012 - 09:49 PM
thepowdertoy #1
Posted 07 June 2012 - 11:49 PM
so I was trying to make a computercraft controller for direwolf20 quarry, here is the code:

cycle = "cycle"

print("quarry 1.0.0")
print("please put a command")

input = read()
if input == cycle then

write("How many times should I loop? ")
local Num = tostring( read() )
for i=1,Num do
print("Looped "..tostring(i).." time(s).")
rs.setBundledOutput("back" , colors.magenta)
sleep(1.0)
rs.setbundledOutput("back" , colors.yellow)
sleep(1.0)
end
end

What it should do is to first display quarry 1.0.0 and please put a command, then we need to type cycle, then that how many times should I loop appear, then we should type a number, then the magenta wire and yellow color will blink alternately.
MysticT #2
Posted 08 June 2012 - 12:44 AM
I fixed the code and commented the changes:

print("quarry 1.0.0")
print("please put a command")

local input = read()
if input == "cycle" then
  write("How many times should I loop? ")
  local Num = tonumber(read()) -- use tonumber() to convert the input to a number, not tostring()
  for i = 1, Num do
    print("Looped ", i, " time(s).")
    rs.setBundledOutput("back" , colors.magenta)
    sleep(1.0)
    rs.setBundledOutput("back" , colors.yellow) -- typo: you wrote rs.setbundledOutput with b instead of B
    sleep(1.0)
  end
end
thepowdertoy #3
Posted 08 June 2012 - 03:08 AM
thanks now it works