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

Need Help With Error in Strip Mining Code

Started by forgottenshdw, 18 February 2013 - 09:23 PM
forgottenshdw #1
Posted 18 February 2013 - 10:23 PM
Title: Need Help With Error in Strip Mining Code

I made this code to use on multiple turtles to stripmine a large area but i keep getting the same error no matter what i do. I made a simplier code with the some idea of using a function and a for loop to work but i cant seem to get this to work. HELP.

the error is bios:338: [string "mine"]:7: '(' expected

and the code is this

local a = 0
write("Distance")
input = read()
a = input

function mine
turtle.dig()
turtle.up()
turtle.dig()
turtle.up()
turtle.dig()
turtle,forward()
turtle.down(2)
end

for i = 1, a do
mine
end
turtle.back(a)

Thank You
remiX #2
Posted 19 February 2013 - 04:39 AM
Declaring a function you need ()

local function mine()
-- code
end

And to call it
mine()

local a = 0
write("Distance")
input = read()
a = tonumber(input) -- tonumber the input - at the moment, it's a string

function mine()
turtle.dig()
turtle.up()
turtle.dig()
turtle.up()
turtle.dig()
turtle.forward()
turtle.down(2)
end

for i = 1, a do
mine()
end

-- turtle.back does nothing with arguments
for i = 1, a do
	turtle.back()
end
forgottenshdw #3
Posted 19 February 2013 - 08:48 AM
Thanks for the help. It works like a charm now.