Posted 14 May 2013 - 01:12 AM
Everything is wrong, well, maybe not but still. I usually try and figure things out myself but I can't get this one.
Here is my code.
Old Issue:
Currently I am getting '=' expected on line 8 "
But obviously that is wrong
Current Issue:
Program does not function in it's current state, I feel it may be a syntax issue, but I can't figure it out.
I believe it is somewhere in this part of the code where everything goes to hell.
Here is my code.
Spoiler
term.clear()
--Pre-operational message to go here
--ask how many trees or how long to run
--log of tree in 1, sapling in 2, bm in 3
--Memory
local bm = turtle.getItemCount(3)
local z = 0
local x = 0
local step = 0
local tc = nil
local t = 0
local pt = 0
--Memory Functions
local function df() -- Dig Forward
pt = (t)
turtle.dig()
if true then
turtle.forward()
if true then
z = (z+1)
end
end
end
local function rn() -- Return
turtle.back()
if true then
z = (z-1)
end
end
local function du() -- Dig Up
turtle.digUp()
if true then
turtle.up()
if true then
x = (x+1)
end
end
end
local function tc() -- Tree check
turtle.select(1)
if turtle.compare() then
tc = 1
end
if not turtle.compare() then
tc = 0
end
end
local function bt() -- Bonemeal true
tc()
if (tc == 0) then
print("It appears there is no tree")
turtle.select(2)
if not turtle.compare() then
turtle.place()
print("Sapling Planted")
turtle.select(3)
turtle.place()
print("Bonemeal Deployed")
end
if turtle.compare() then
turtle.select(3)
turtle.place()
print("Bonemeal Deployed")
return true
end
end
if (tc == 1) then
return true
end
end
local function bf() -- Bonemeal false
tc()
if (tc == 0) then
print("It appears there is no tree")
turtle.select(2)
if not turtle.compare() then
turtle.place()
print("waiting for the tree to grow now, sir")
sleep(300)
end
if turtle.compare() then
print("waiting for the tree to grow, sir")
sleep(300)
end
end
if (tc == 1) then
print("Tree has grown")
end
end
local function timber() -- Cut down tree
if (step ~= 1) then
print("something messed up")
end
if (z == 0) and (x == 0) and (step == 1) and (tc == 1) then
df()
step = 2
end
while (z == 1) and (step == 2) and turtle.detectUp() do
du()
end
while (z == 1) and (step == 2) and not turtle.detectUp() and not turtle.detectDown() do
turtle.down()
t = (t+1)
end
if (z == 1) and turtle.detectDown() and not turtle.detectUp() and (t > pt) then
rn()
step = 3
print("Haha, no more tree")
print("I'm going to rest for a minute")
sleep(60)
end
end
local function wl() -- Waiting loop
tc()
while (tc == 0) do
sleep(300)
tc()
end
if (tc == 1) then
return true
end
end
--The actual lumbering part
if (bm > 2) and (z == 0) then
bt()
if true then
step = 1
timber()
end
else
print("At least 2 bonemeals are required to fertilize")
end
if (bm < 2) and (z == 0) then
bf()
if (tc == 0) then
wl()
if true then
step = 1
timber()
end
end
if (tc == 1) then
step = 1
timber()
end
else
print("Cannot operate, is there a foreign object in front of turtle?")
print("Remember: Log in first slot, Sapling in second, and Bonemeal in third")
end
Old Issue:
Spoiler
This issue has been SOLVED, NEW issue belowCurrently I am getting '=' expected on line 8 "
local bm = turtle.getItemCount(3)
But obviously that is wrong
Current Issue:
Program does not function in it's current state, I feel it may be a syntax issue, but I can't figure it out.
I test the program by placing the materials in the correct slots, the turtle on flat ground and run the program.
What it should do is plant a sapling, and given there is enough bonemeal, fertilize it and then immediately cut it down.
If there is not enough bonemeal, it will plant a sapling and then wait until it grows.
I haven't gotten to a point where sapling metadata should be adversely affecting the program but I feel it should be relatively easy to fix, by making the turtle assign a value to a variable when it plants a sapling, to know that it has planted a sapling there.
But for some reason, there is something causing the program to fail.
Spoiler
I believe it is somewhere in this part of the code where everything goes to hell.
Spoiler
--The actual lumbering part
if (bm > 2) and (z == 0) then
bt()
if true then
step = 1
timber()
end
else
print("At least 2 bonemeals are required to fertilize")
end
if (bm < 2) and (z == 0) then
bf()
if (tc == 0) then
wl()
if true then
step = 1
timber()
end
end
if (tc == 1) then
step = 1
timber()
end
else
print("Cannot operate, is there a foreign object in front of turtle?")
print("Remember: Log in first slot, Sapling in second, and Bonemeal in third")
end
Edited by