This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
jakemg's profile picture

then expected when already have then in the function!?!

Started by jakemg, 05 April 2013 - 08:08 AM
jakemg #1
Posted 05 April 2013 - 10:08 AM
error on line 50 'then' expected


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
Telokis #2
Posted 05 April 2013 - 10:12 AM
When you see "Error on line 50", why don't you check your 50'th line ?
Telokis #3
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
Left #4
Posted 05 April 2013 - 10:16 AM
If distance = >

needs to be

If distance =>
Telokis #5
Posted 05 April 2013 - 10:18 AM
If distance = > needs to be If distance =>

More like

if distance >= 0 then

I think
jakemg #6
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


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
Telokis #7
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 ?
jakemg #8
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
OmegaVest #9
Posted 05 April 2013 - 10:36 AM
EDIT: Wow I type slow. Ignore this.
jakemg #10
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()

Telokis #11
Posted 05 April 2013 - 11:06 AM
I think you shouldn't reset your distance variable in loop. Declare it before the "for" statement !
jakemg #12
Posted 05 April 2013 - 11:10 AM
Um could you explain it a little further?
Telokis #13
Posted 05 April 2013 - 11:12 AM
Well :

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 ! ;)/>
jakemg #14
Posted 05 April 2013 - 11:14 AM
So all i have to do is put distance = 0 above my for i = 1, times do
jakemg #15
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 :

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()

Telokis #16
Posted 05 April 2013 - 12:02 PM
What does it actually do ?
SuicidalSTDz #17
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:

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
jakemg #18
Posted 05 April 2013 - 12:06 PM
You lost me so you want me to put my loop after I call the empty function?
SuicidalSTDz #19
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)
jakemg #20
Posted 05 April 2013 - 12:10 PM
is that exactly what i have
SuicidalSTDz #21
Posted 05 April 2013 - 12:11 PM
Mhmm, does your Empty function continue on? Or does it stop there? I can't tell.
jakemg #22
Posted 05 April 2013 - 12:11 PM
nvm thank you I see what you did
jakemg #23
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
SuicidalSTDz #24
Posted 05 April 2013 - 12:13 PM
I guess I could take a look ^_^/>