Jump to content




Attempt to call nil


  • You cannot reply to this topic
2 replies to this topic

#1 thepowdertoy

  • Members
  • 20 posts

Posted 07 June 2012 - 10: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.

#2 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 07 June 2012 - 11:44 PM

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


#3 thepowdertoy

  • Members
  • 20 posts

Posted 08 June 2012 - 02:08 AM

thanks now it works





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users