2 posts
Posted 12 April 2014 - 06:55 PM
My program has two seperate functions that sometimes when i use one input it completes that function and does the next one without any seperate input. but when i use end twice i get a bios 339.
my code is here
http://pastebin.com/mceNvrY2
7083 posts
Location
Tasmania (AU)
Posted 13 April 2014 - 12:03 AM
The first "end" in your script probably shouldn't be located where it is.
Here's a bit of a re-write, which tries not to ditch your original structure entirely. Note how the indendation makes it very easy to see where each block ("if" / "for" / "elseif") starts and ends. You can hopefully see how you might trim it down further.
Spoiler
print("Please enter square size:")
local size = tonumber(read())
print("\"q\" for a walkway, \"r\" to just dig:")
local input = read()
turtle.select(1)
if input == "q" then
for j=1,4 do
for i = 1,size do
turtle.dig()
turtle.forward()
turtle.digDown()
turtle.placeDown()
end
turtle.turnRight()
if j == 2 then turtle.select(2) end
end
elseif input == "r" then
for j=1,4 do
for i = 1,size do
turtle.dig()
turtle.forward()
turtle.digDown()
end
turtle.turnRight()
if j == 2 then turtle.select(2) end
end
end
print("You're Welcome")
2 posts
Posted 13 April 2014 - 01:12 AM
Thank you so much. Im new to lua and was wondering if you could put sidenotes next to the commands with the small explanation so I can understand the full code and implement that into later projects.