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

Using multiple arguments for a dig program

Started by Emil, 10 August 2013 - 02:19 AM
Emil #1
Posted 10 August 2013 - 04:19 AM
Title: Using multiple arguments for a dig program

I want to use the same program to dig up, down and forward. It always gives me the error message that I put after the last else even though I type: dig forward 4


local args={...}
local arg1=args[1]
local arg2=args[2]
if arg1 == forward then
  for i=1,tonumber(arg2) do
    turtle.dig()
    turtle.forward()
  end
elseif arg1 == down then
  for i=1,tonumber(arg2) do
    turtle.digDown()
    turtle.down()
  end
elseif arg1 == up then
  for i=1,tonumber(arg2) do
    turtle.digUp()
    turtle.up()
  end
else
  print("Usage: dig forward/up/down amountofblocks.")
end
Bubba #2
Posted 10 August 2013 - 10:13 AM
Split into new topic.
CometWolf #3
Posted 11 August 2013 - 06:59 AM
you forgot quotations around your strings when comparing them

local args={...}
local arg1=args[1]
local arg2=args[2]
if arg1 == "forward" then --here
  for i=1,tonumber(arg2) do
	turtle.dig()
	turtle.forward()
  end
elseif arg1 == "down" then --here
  for i=1,tonumber(arg2) do
	turtle.digDown()
	turtle.down()
  end
elseif arg1 == "up" then -- and here
  for i=1,tonumber(arg2) do
	turtle.digUp()
	turtle.up()
  end
else
  print("Usage: dig forward/up/down amountofblocks.")
end
Emil #4
Posted 11 August 2013 - 07:25 AM
you forgot quotations around your strings when comparing them

local args={...}
local arg1=args[1]
local arg2=args[2]
if arg1 == "forward" then --here
  for i=1,tonumber(arg2) do
	turtle.dig()
	turtle.forward()
  end
elseif arg1 == "down" then --here
  for i=1,tonumber(arg2) do
	turtle.digDown()
	turtle.down()
  end
elseif arg1 == "up" then -- and here
  for i=1,tonumber(arg2) do
	turtle.digUp()
	turtle.up()
  end
else
  print("Usage: dig forward/up/down amountofblocks.")
end

Thank you very much.