Help please. Simple tunnel script not working properly
#1
Posted 23 January 2013 - 07:49 AM
I've been trying to learn lua for a couple weeks now in my off time and without much progress. I was hoping one of you more helpful fellas could give me a tip or two on how to fix / improve this script.
right now ive been getting the error "end" expected to close 'function' at line :3:
This is confusing the crap out of me... Thanks in advance.
#2
Posted 23 January 2013 - 07:56 AM
There is a couple spelling errors in that, so try this:
Checking right now...
#3
Posted 23 January 2013 - 08:05 AM
--[[ Go ]]--
function checkBlocks()
if turtle.detectUp() then
turtle.digUp()
end
if turtle.detectDown() then
return true
elseif not turtle.detectDown() then
turtle.select(1)
sleep(0.375)
turtle.placeDown()
end
end
function moveForward()
checkBlocks()
sleep(0.375)
if not turtle.forward() then
turtle.dig()
turtle.forward()
end
end
function tunnel()
input = read()
print("tunneling "..input.." blocks deep...")
for moved = 1, tonumber(input) do
moveForward()
end
moved = 0
print("Finished!!")
sleep(3)
end
print("How many spaces? ")
tunnel()
-- i know i suck at this...
#4
Posted 23 January 2013 - 08:10 AM
MudkipTheEpic, on 23 January 2013 - 07:56 AM, said:
There is a couple spelling errors in that, so try this:
Checking right now...
Thanks for that, it fixed the end error. However the script is supposed to fill in 1 block deep gaps below the turtle and skips every othe gap below.
Also, i read through the changes and i cant find exactly what you changed... :/ mind giving me a clue, i just dont see it...
NM, thx for the clarification
Edited by le nub, 23 January 2013 - 08:11 AM.
#6
Posted 23 January 2013 - 08:17 AM
Willibilly19, on 23 January 2013 - 08:05 AM, said:
--[[ Go ]]--
function checkBlocks()
if turtle.detectUp() then
turtle.digUp()
end
if turtle.detectDown() then
return true
elseif not turtle.detectDown() then
turtle.select(1)
sleep(0.375)
turtle.placeDown()
end
end
function moveForward()
checkBlocks()
sleep(0.375)
if not turtle.forward() then
turtle.dig()
turtle.forward()
end
end
function tunnel()
input = read()
print("tunneling "..input.." blocks deep...")
for moved = 1, tonumber(input) do
moveForward()
end
moved = 0
print("Finished!!")
sleep(3)
end
print("How many spaces? ")
tunnel()
-- i know i suck at this...
AH, i suspected i was calling it twice, that explains why he was skipping those fillers below too. I really appreciate your help dude, and everybody else.
Next time i ask for help ill try to find my own spelling errors...
#7
Posted 23 January 2013 - 08:18 AM
ChunLing, on 23 January 2013 - 08:10 AM, said:
thanks. im slow sometimes....
#8
Posted 23 January 2013 - 08:24 AM
le nub, on 23 January 2013 - 08:17 AM, said:
Next time i ask for help ill try to find my own spelling errors...
No problem. I just threw the code onto my turtle and checked it for you. Glad I could be of help. btw, it's a decent script for just starting:P
#9
Posted 23 January 2013 - 08:31 AM
Willibilly19, on 23 January 2013 - 08:24 AM, said:
le nub, on 23 January 2013 - 08:17 AM, said:
Next time i ask for help ill try to find my own spelling errors...
No problem. I just threw the code onto my turtle and checked it for you. Glad I could be of help. btw, it's a decent script for just starting:P
Decent... oh, thats a relief. Ive only ever written 2 other smaller and simpler scripts. So im quite new to this. Thanks, i think ill take that as a compliment.
Just out of curiosity.. How would you have written a program to do the same thing? Sorry if this is a little too much to ask for.. But im really curious to see how someone else might use different methods to achieve this more efficiently.
#10
Posted 23 January 2013 - 08:44 AM
#11
Posted 23 January 2013 - 08:46 AM
#12
Posted 23 January 2013 - 08:57 AM
Willibilly19, on 23 January 2013 - 08:46 AM, said:
I did look at your page. it has some very nice stuff. I like how your code is very simple to read and cleanly. Maybe you could explain to me the function of tArgs {...} in your quarry? I see that used a lot so i figure its helpful. I get that its setting up a table but after that im not sure what task its performing... Sorry if im killing you with Q's.. a link or pointer to something relevant would be great instead if your not up to explaining the nub stuff..
Thanks so much
#13
Posted 23 January 2013 - 09:04 AM
tArgs = {...}
length = tArgs[1]
if #tArgs ~= 1 then
print("Usage: branch <length>")
end
local function forward()
while not turtle.forward() do
turtle.dig()
turtle.digUp()
turtle.attack()
end
end
local function tunnel()
forward()
if not turtle.detectDown() then
turtle.select(1)
turtle.placeDown()
end
end
for i = 1,length do
tunnel()
end
turtle.digUp()
for i = 1,length do
turtle.back()
end
I'd probably add some more to it, but that would be the basic code.
#14
Posted 23 January 2013 - 09:05 AM
#15
Posted 23 January 2013 - 09:37 AM
Willibilly19, on 23 January 2013 - 09:04 AM, said:
tArgs = {...}
length = tArgs[1]
if #tArgs ~= 1 then
print("Usage: branch <length>")
end
local function forward()
while not turtle.forward() do
turtle.dig()
turtle.digUp()
turtle.attack()
end
end
local function tunnel()
forward()
if not turtle.detectDown() then
turtle.select(1)
turtle.placeDown()
end
end
for i = 1,length do
tunnel()
end
turtle.digUp()
for i = 1,length do
turtle.back()
end
I'd probably add some more to it, but that would be the basic code.
Thanks for that. I think i get it except for the tArgs once again.. I also sent you my Skype via PM in case you ever want to chat or exchange ideas.. im still pretty nub so i dont know if ill have anything useful but i can try
#16
Posted 23 January 2013 - 05:01 PM
Basically, when you run a program, the shell loads the file as a function with a variable argument list, so that you can pass in command line parameters (such as "go fd 3" using the go program). If you want to use those passed in parameters in your program, then you need to assign the argument table to an identifier so that you can use the normal table access methods to get the values in the table.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











