Posted 29 September 2012 - 09:22 AM
Hi, I wrote a simple program to automate a reed farm. I am rather new to lua and I'm having problems with syntax, especially when trying to call a function through another function.
From the information on the reference manual, I believe that you can perform such operation with a line similar to the following:
f = turtle.forward()
Afterwards, to call function f
if something then
f()
end
But apparently I have it all wrong, I cannot get the program below to work (despite it being stupidly simple). Any help you guys could provide would be greatly appreciated.
I gave up after many failed attempts at correcting it. My main concern is knowing how to call a function through another function, so i can "rename" the ones provided by default.
From the information on the reference manual, I believe that you can perform such operation with a line similar to the following:
f = turtle.forward()
Afterwards, to call function f
if something then
f()
end
But apparently I have it all wrong, I cannot get the program below to work (despite it being stupidly simple). Any help you guys could provide would be greatly appreciated.
local function dig()
turtle.dig()
end
local function digU()
turtle.digUp()
end
local function digD()
turtle.digDown()
end
local function det()
return turtle.detect()
end
local function detD()
return turtle.detectDown()
end
local function detU()
return turtle.detectUp()
end
local function fwd()
turtle.forward()
end
local function back()
turtle.back()
end
local function up()
turtle.up()
end
local function down()
turtle.down()
end
local function tR()
turtle.turnRight()
end
local function tL()
turtle.turnLeft()
end
local function rowReed()
for n=1,16 do
if det() then
dig()
else
fwd()
end
end
end
local function levelReed()
rowReed()
fwd()
tR()
fwd()
fwd()
tR()
rowReed()
fwd()
tL()
fwd()
tL()
rowReed()
fwd()
tR()
fwd()
fwd()
tR()
rowReed()
fwd()
tR()
fwd()
fwd()
fwd()
fwd()
fwd()
fwd()
tR()
end
local function floorReed()
levelReed()
down()
levelReed()
end
function reed(nFloor)
down()
down()
down()
for i=1,nFloor do
floorReed()
down()
down()
down()
down()
end
for j=1,nFloor do
for k=1,5 do
up()
end
end
for m=1,16 do
turtle.select(m)
turtle.drop()
end
end
I gave up after many failed attempts at correcting it. My main concern is knowing how to call a function through another function, so i can "rename" the ones provided by default.