Can Someone Help Me In My Program
#1
Posted 17 September 2013 - 06:17 AM
here http://www.computerc...mining-turtle/. This Topic can be close now.
Source code
http://pastebin.com/emb9EnUC
#2
Posted 17 September 2013 - 08:45 AM
You have called a function while defining that function
You have also called a function before defining it
--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
#3
Posted 17 September 2013 - 09:05 AM
#5
Posted 17 September 2013 - 09:12 AM
LBPHacker, on 17 September 2013 - 09:07 AM, said:
Calling it in itself? Possible if it's declared like
local function x(...and not like
local x = function(...Beware of filling stacks though. And use locals.
Are you able to call functions before declaring them? e.g.,
myFunction()
function myFunction()
print("Would this run?")
end
#7
#8
Posted 17 September 2013 - 09:51 AM
#9
Posted 17 September 2013 - 10:06 AM
Quote
#10
Posted 17 September 2013 - 08:30 PM
Cranium, on 17 September 2013 - 10:06 AM, said:
Thank you
johnneijzen, on 17 September 2013 - 09:51 AM, said:
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
#11
Posted 18 September 2013 - 07:11 AM
campicus, on 17 September 2013 - 08:30 PM, said:
Cranium, on 17 September 2013 - 10:06 AM, said:
Thank you
johnneijzen, on 17 September 2013 - 09:51 AM, said:
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
I have follow your code and thank you i have it working.
http://pastebin.com/5DPjqTbC
#12
Posted 18 September 2013 - 07:21 AM
because i want: when turtle.forward() is true then do TF = TF - 1. so distance wont get messup
#13
Posted 18 September 2013 - 08:31 PM
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.
As far as knowing for sure if you turtle has moved, you should read http://computercraft...ki/Turtle_(API) so that your eyes may be opened wide. But yes you can detect if the turtle moved forward. Replace lines 20-21 with this code
if turtle.forward() then TF = TF -1 end
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











