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

Need help Debugging EOF

Started by loganic, 30 June 2013 - 04:30 PM
loganic #1
Posted 30 June 2013 - 06:30 PM
I understand eof typically means I have one too many 'end', I dont think it does, so one of my functions doesn't seem to be reading then. I've done my best to format it to help make it easier.

Some background. I'm building a HS railroad, which every 6th block, has a powered track, and adjacent redstone torch + regular torch.
I plan on arranging brick slots 1-8, regular track 9-13, powered track 14, redstone torch 15, and regular torch 16.

I also bastardized some code from a platform script a friend wrote. Because of that I understand it's not really optimized.
The turtle should lay bricks, and then go up and put tracks & torchs.
Can someone help me find it?

local fulllength = 6
local partiallength = fulllength -1
local crosslength = 3

local blockslot = 1
local trackslot = 9
local poweredslot = 14
local rstorchslot = 15
local torchslot =16
local slot = 1
local continue = true
turtle.select(blockslot)


turtle.dig()

turtle.forward()

while
continue == true do
for j = 1, fulllength, 1 do


slot = blockslot
if turtle.getItemCount(slot) == 0 then
slot = slot + 1

blockslot = blockslot +1
turtle.select(slot)

if turtle.getItemCount(slot) == 0 then
continue = false
end
turtle.digDown()
turtle.placeDown()

else
turtle.digDown()

turtle.placeDown()

end

if j < fulllength then

turtle.dig()

turtle.forward()

end

end

turtle.back()
turtle.turnRight()
turtle.forward()
if turtle.getItemCount(slot) == 0 then
slot = slot + 1

blockslot = blockslot +1
turtle.select(slot)

if turtle.getItemCount(slot) == 0 then
continue = false
end
turtle.digDown()
turtle.placeDown()

else
turtle.digDown()

turtle.placeDown()

end

turtle.back()
turtle.back()
if turtle.getItemCount(slot) == 0 then
slot = slot + 1

blockslot = slot
turtle.select(slot)

if turtle.getItemCount(slot) == 0 then
continue = false
end
turtle.digDown()
turtle.placeDown()

else
turtle.digDown()

turtle.placeDown()

end

turtle.forward()
turtle.turnLeft()
turtle.up()
for j = 1, fulllength, 1 do
turtle.back()
end
for j = 1, partiallength, 1 do


slot = trackslot
if turtle.getItemCount(slot) == 0 then
slot = slot + 1

trackslot = slot
turtle.select(slot)

if turtle.getItemCount(slot) == 0 then
continue = false
end
turtle.digDown()
turtle.placeDown()

else
turtle.digDown()

turtle.placeDown()

end

if j < partiallength then

turtle.dig()

turtle.forward()

end

end



turtle.turnRight()
turtle.forward()
slot = rstorchslot
turtle.select(slot)

if turtle.getItemCount(slot) == 0 then
continue = false
else
turtle.digDown()

turtle.placeDown()

end

turtle.back()
turtle.back()
slot = torchslot
turtle.select(slot)

if turtle.getItemCount(slot) == 0 then
continue = false
else
turtle.digDown()

turtle.placeDown()

end
turtle.forward()
turtle.turnLeft()
turtle.down()
turtle.forward()
end

end
Lyqyd #2
Posted 01 July 2013 - 02:01 PM
Split into new topic.

Proper indentation is the biggest way to help prevent end expected and eof expected errors. For every block you open that requires an end, indent one level. When you put an end, un-indent one level (so the end is on the level of the statement it matches). It's easy to visually see where you have two ends on one level, or and end trying to dive off the left side of the document, etc.
albrat #3
Posted 02 July 2013 - 05:13 AM
I suggest to everyone who wants to debug a script with errors… Please get a copy of Notepad ++ :D/>/> great free tool that has language translations built into it. This colours and sorts code into blocks ( puts a + by every opening statement ) so you can visually see where each if / while / for statement opens and closes…

I am finding it difficult to read the program so I started to re-write it with indentations, comments.. (opening and closing comments for each end statement)

did you copy and paste some code for this ? You seem to have ended the while .. do loop in the middle of the program. Approx line 74 is the end of the program.

I marked the point where I think you have an extra end statement in your code. ( I think you could call some of the empty slot checks as a function. This would reduce your code length and make it much neater. )
Spoilerlocal fulllength = 6
local partiallength = fulllength -1
local crosslength = 3

local blockslot = 1
local trackslot = 9
local poweredslot = 14
local rstorchslot = 15
local torchslot =16
local slot = 1
local continue = true
turtle.select(blockslot)


turtle.dig()

turtle.forward()

while
continue == true do
for j = 1, fulllength, 1 do


slot = blockslot
if turtle.getItemCount(slot) == 0 then
slot = slot + 1

blockslot = blockslot +1
turtle.select(slot)

if turtle.getItemCount(slot) == 0 then
continue = false
end
turtle.digDown()
turtle.placeDown()

else
turtle.digDown()

turtle.placeDown()

end

if j < fulllength then

turtle.dig()

turtle.forward()

end

end

turtle.back()
turtle.turnRight()
turtle.forward()
if turtle.getItemCount(slot) == 0 then
slot = slot + 1

blockslot = blockslot +1
turtle.select(slot)

if turtle.getItemCount(slot) == 0 then
continue = false
end
turtle.digDown()
turtle.placeDown()

else
turtle.digDown()

turtle.placeDown()

end

–[[ Program ends here at this end point.
********************************************************************
–]]

{snip} more program fillows but I ran out of chars….

function code I made for the check.
Spoilerlocal curslot = 0
local empty = false

local maxslot = 11




function checkturt(maxslot)

for c = 1, maxslot do

curslot = turtle.getItemCount© – get the current slot item count.
if curslot ~= 0 then return false, c end – is it empty ?
end – end if loop
c = 0 – We finished with no empty slots
return true, c – return true and end the while loop
end


while not empty do
empty, c = checkturt(maxslot)
– this will loop untill the return is true. Then the program stops.

– add your code here.
– Note this code will error out even if you have items because the
– program sits doing nothing while the contidions are true untill
– you add the program that makes the turtle do stuff.

end

print("out of items… Error")
albrat #4
Posted 02 July 2013 - 06:46 AM
Btw to use the above function at any time … type the following command :-

"empty, c = checkturt(maxslot)"

this will automatically end the program if the return is true. (which means the turtle is out of items)
Also if you call this after every action the turtle will always place items at the right times