here http://www.computercraft.info/forums2/index.php?/topic/15292-john-strip-mining-turtle/. This Topic can be close now.
Source code
http://pastebin.com/emb9EnUC
--Start
print("Hi There Welcome to Mining Turtle Program")
print("How Far Will Turtle Go")
local U = tonumber(read())
local TF = U --two variables that are exactly the same? just make this one variable
local TB = U
forwardM() -- calling your function here before defining it
--Mining
function forwardM()
turtle.dig()
turtle.forward()
while true do
TF = TF - 1
turtle.digUp()
end
if TF == 0 then
backA()
else
forwardM() --you are calling your function within your definition of that function
end
end
--Warm Up For Back Program
function backA()
turtle.turnLeft()
turtle.turnLeft()
back()
end
--Back Program
function back()
turtle.forward()
while true do
TB = TB - 1
end
if TB == 0 then
print("Turtle done")
else
back()
end
end
local function x(...
and not likelocal x = function(...
Beware of filling stacks though. And use locals.Calling it before declaring it? Yeah, that's wrong.
Calling it in itself? Possible if it's declared likeand not likelocal function x(...
Beware of filling stacks though. And use locals.local x = function(...
myFunction()
function myFunction()
print("Would this run?")
end
Are you able to call functions before declaring them?
Calling it before declaring it? Yeah, that's wrong.
Are you able to call functions before declaring them?Calling it before declaring it? Yeah, that's wrong.
You cannot call a function before declaring it. It is incorrect usage to do so.Your pronoun use is confusing me lol Is my advice wrong or is calling before declaring wrong?
-snip-
local distance = 0
-- Start
print("Hi There Welcome to Mining Turtle Program")
print("How Far Will Turtle Go")
input = io.read()
distance = tonumber(input)
TF = distance
TB = distance
forwardM()
while true do
TF = TF - 1
turtle.digUp()
end
repeat
TF = TF - 1
turtle.digUp()
until TF == 0
-snip-
Thank you :)/>
try something like this:local distance = 0 -- Start print("Hi There Welcome to Mining Turtle Program") print("How Far Will Turtle Go") input = io.read() distance = tonumber(input) TF = distance TB = distance forwardM()
Also, this loop will run forever:while true do TF = TF - 1 turtle.digUp() end
A repeat loop would be better:repeat TF = TF - 1 turtle.digUp() until TF == 0
backA()
because TF will equal 0 after the repeat loop is finished and because of that the forwardM()
will never get executed. If you want it to get executed you will have to rework the logic of the forwardM() function.
if turtle.forward() then
TF = TF -1
end