local args = {...}
local times = tonumber(args[1]) -- this is how many times we want
for i=1, times do
distance=distance
function empty()
if turtle.getItemCount(16) > 15 then
turtle.digUp()
turtle.placeUp(1)
for i=1,16 do
turtle.dropUp(i)
turtle.select(1)
end -- ending the for
turtle.digUp()
end -- ending the if
end
function dig()
turtle.select(1)
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.up()
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.digDown()
turtle.down()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.up()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnRight()
turtle.digDown()
turtle.down()
distance = distance + 1
end
function turn()
turtle.turnLeft()
turtle.turnLeft()
end
function home()
if distance = > 0 then
turtle.forward()
distance = distance - 1
end
end
dig()
empty()
end
turn()
home()
end
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
then expected when already have then in the function!?!
Started by jakemg, 05 April 2013 - 08:08 AMPosted 05 April 2013 - 10:08 AM
error on line 50 'then' expected
Posted 05 April 2013 - 10:12 AM
When you see "Error on line 50", why don't you check your 50'th line ?
Posted 05 April 2013 - 10:14 AM
Well, I'm sorry, I see why you weren't able to find the error. It is not the 50 but the 46 which is bad :
if distance = > 0 then
Posted 05 April 2013 - 10:16 AM
If distance = >
needs to be
If distance =>
needs to be
If distance =>
Posted 05 April 2013 - 10:18 AM
If distance = > needs to be If distance =>
More like
if distance >= 0 then
I think
Posted 05 April 2013 - 10:29 AM
@Ninetainedo your string was correct
but now i have new error it goes through my function dig() until the end once it mines like 4 blocks it says
:41: attempt to perform arithmetic __ and on nil and number
line 41 is distance = distance + 1
but now i have new error it goes through my function dig() until the end once it mines like 4 blocks it says
:41: attempt to perform arithmetic __ and on nil and number
line 41 is distance = distance + 1
local args = {...}
local times = tonumber(args[1]) -- this is how many times we want
for i=1, times do
distance=distance
function empty()
if turtle.getItemCount(16) > 15 then
turtle.digUp()
turtle.placeUp(1)
for i=1,16 do
turtle.dropUp(i)
turtle.select(1)
end -- ending the for
turtle.digUp()
end -- ending the if
end
function dig()
turtle.select(1)
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.up()
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.digDown()
turtle.down()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.up()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnRight()
turtle.digDown()
turtle.down()
distance = distance + 1 --this is line 41
end
function turn()
turtle.turnLeft()
turtle.turnLeft()
end
function home()
if distance >= 0 then
turtle.forward()
distance = distance - 1 --if 41 had an error I think this will 2
end
end
dig()
empty()
end
turn()
home()
end
Posted 05 April 2013 - 10:32 AM
distance=distance
Your fourth line is this one. You should do something like
distance = 0
Do you see why ?
Posted 05 April 2013 - 10:35 AM
Hmm K ya i see now but I remember i have used distance = distance before hmm what ever thanks
Posted 05 April 2013 - 10:36 AM
EDIT: Wow I type slow. Ignore this.
Posted 05 April 2013 - 10:42 AM
Okay now my turtle isnt come back all the way it just turn around then goes forward once. I dont think its adding or subtracting from distance
local args = {...}
local times = tonumber(args[1]) -- this is how many times we want
for i=1, times do
distance = 0
function empty()
if turtle.getItemCount(16) > 15 then
turtle.digUp()
turtle.placeUp(1)
for i=1,16 do
turtle.dropUp(i)
turtle.select(1)
end -- ending the for
turtle.digUp()
end -- ending the if
end
function dig()
turtle.select(1)
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.up()
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.digDown()
turtle.down()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.up()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnRight()
turtle.digDown()
turtle.down()
distance = distance + 2
end
function turn()
turtle.turnLeft()
turtle.turnLeft()
end
function home()
if distance >= 0 then
turtle.forward()
distance = distance - 1
else print ("im home")
end
end
dig()
empty()
end
turn()
home()
Posted 05 April 2013 - 11:06 AM
I think you shouldn't reset your distance variable in loop. Declare it before the "for" statement !
Posted 05 April 2013 - 11:10 AM
Um could you explain it a little further?
Posted 05 April 2013 - 11:12 AM
Well :
Declares a loop. Everything under this (until the "end" corresponding to the "for") will be executed each time we enter in the loop.
If you write
In your loop, it will be reset to 0 each time !
I think this is not what you want ! ;)/>
for i = 1, times do
Declares a loop. Everything under this (until the "end" corresponding to the "for") will be executed each time we enter in the loop.
If you write
distance = 0
In your loop, it will be reset to 0 each time !
I think this is not what you want ! ;)/>
Posted 05 April 2013 - 11:14 AM
So all i have to do is put distance = 0 above my for i = 1, times do
Posted 05 April 2013 - 11:16 AM
No I just tried it that didnt work im so lost I dont get why this is doing this
Current code :
Current code :
local args = {...}
local times = tonumber(args[1]) -- this is how many times we want
distance = 0
for i=1, times do
function empty()
if turtle.getItemCount(16) > 15 then
turtle.digUp()
turtle.placeUp(1)
for i=1,16 do
turtle.dropUp(i)
turtle.select(1)
end -- ending the for
turtle.digUp()
end -- ending the if
end
function dig()
turtle.select(1)
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.up()
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.digDown()
turtle.down()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.up()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnRight()
turtle.digDown()
turtle.down()
distance = distance + 2
end
function turn()
turtle.turnLeft()
turtle.turnLeft()
end
function home()
if distance >= 0 then
turtle.forward()
distance = distance - 1
else print ("im home")
end
end
dig()
empty()
end
turn()
home()
Posted 05 April 2013 - 12:02 PM
What does it actually do ?
Posted 05 April 2013 - 12:03 PM
The function 'empty' will never work being in a loop. You are changing everything in it before you call it.. Put your for loop in the empty function and try that.
Here:
Here:
function empty()
for i=1, times do
if turtle.getItemCount(16) > 15 then
turtle.digUp()
turtle.placeUp(1)
for i=1,16 do
turtle.dropUp(i)
turtle.select(1)
end -- ending the for
turtle.digUp()
end -- ending the if
end -- ending your for
end
Posted 05 April 2013 - 12:06 PM
You lost me so you want me to put my loop after I call the empty function?
Posted 05 April 2013 - 12:08 PM
Read above, I posted code for you to enthral yourself in.
EDIT: I can't really read the unindented code so I am not fully aware of where you are ending each block (if's, functions, etc)
EDIT: I can't really read the unindented code so I am not fully aware of where you are ending each block (if's, functions, etc)
Posted 05 April 2013 - 12:10 PM
is that exactly what i have
Posted 05 April 2013 - 12:11 PM
Mhmm, does your Empty function continue on? Or does it stop there? I can't tell.
Posted 05 April 2013 - 12:11 PM
nvm thank you I see what you did
Posted 05 April 2013 - 12:12 PM
also do you know how to fix my distance problem i posted it here
http://www.computercraft.info/forums2/index.php?/topic/11851-turtle-not-adding-or-subtracting-from-distance/
cause i have no idea how to fix that haha
http://www.computercraft.info/forums2/index.php?/topic/11851-turtle-not-adding-or-subtracting-from-distance/
cause i have no idea how to fix that haha
Posted 05 April 2013 - 12:13 PM
I guess I could take a look ^_^/>