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

HELP turtle program erros

Started by MasterGAM, 18 May 2014 - 05:34 AM
MasterGAM #1
Posted 18 May 2014 - 07:34 AM
ok so i have been revising a program for a turtle to build a 26 by 26 wall but when I run it it gives me a error
bios:339: [string "build"]:54: 'end' expected (to close function at line 11)
and when i got it to not have that error it would only go through 1 line of placing 26 blocks turn and stop but its suposed to do that 4 time. when i tried to fix that i got the error again.its also supposed to change its selected slot so it can continue build after it uses up the stack but that part wont work either. please tell me all the bugs that are in my program
here is the program


function place()
turtle.back()
turtle.placeDown()
end

function turn()
turtle.back()
turtle.turnLeft()
end

function check()–This is for the changing of the selected slot when the stack runs out
turtle.select(sslot)
sslot = (sslot%16)+1
turtle.select(sslot)
turtle.getItemCount(sslot)
while turtle.getItemCount(sslot) < 1 do
sslot = (sslot%16)
turtle.select(sslot)
end
–Main Program
local sslot = 1
local levels = 0
term.write("How many levels should be created:")
levels = read()
for i =1, levels do

for i =1, 25 do
place()
end
turn()
check()
for i =1, 25 do
place()
end
turn()
check()
for i =1, 25 do
place()
end
turn()
check()
for i =1, 25 do
place()
end
turn()
end

Please help me
RoD #2
Posted 18 May 2014 - 03:05 PM
this should work:

function check()--This is for the changing of the selected slot when the stack runs out
	   turtle.select(sslot)
	   sslot = (sslot%16)+1
	   turtle.select(sslot)
	   turtle.getItemCount(sslot)
	   while turtle.getItemCount(sslot) < 1 do
			  sslot = (sslot%16)
			  turtle.select(sslot)
	   end
end--#You forgot this end to close the function
--Main Program
local sslot = 1
local levels = 0
term.write("How many levels should be created:")
levels = read()
for i =1, levels do
for i =1, 25 do
	   place()
end
	   turn()
	   check()
for i =1, 25 do
	   place()
end
	   turn()
	   check()
for i =1, 25 do
	   place()
end
	   turn()
	   check()
for i =1, 25 do
	   place()
end
	   turn()
end

When making your code use identions (press tab) to be more easy to read the code.
And when posting code in the forums use the < > symbol under the slimy face in the post editor and paste there your code. It will automatically highlight using the lua syntax.
MasterGAM #3
Posted 18 May 2014 - 08:36 PM
thank you but, not i have it working but it keeps stopping after 1 line of blocks instead of making 4, it gives me an error called, turtle:22: Expected number
can you help with this?
Minion #4
Posted 19 May 2014 - 02:21 AM
thank you but, not i have it working but it keeps stopping after 1 line of blocks instead of making 4, it gives me an error called, turtle:22: Expected number
can you help with this?

have you tried cleansing the read() with tonumber()

like levels = tonumber(read())
or levels = tonumber(levels)