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

[Lua][Error] 107: 'end' expected (to close 'if' at line 101)

Started by Frederikam, 29 December 2012 - 02:09 AM
Frederikam #1
Posted 29 December 2012 - 03:09 AM
I am basically having a problem with where I place my "end". I am really not to this as I usually program in Java. Any help is appreciated, especially if you can describe a little more what went wrong.


curFacing = 0
curX = 0
curY = 0
curZ = 0
function fell()
    if turtle.dig() then
	    turtle.dig()
	    turtle.forward()
	    turtle.select(2)
	    turtle.digUp()
	    turtle.up()
	    while turtle.compareUp() == true and turtle.digUp() do
		    turtle.digUp()
		    turtle.up()
	    end
	    while turtle.down() == true do
		   if turtle.getFuelLevel() == 0 then
			   turtle.select(1)
			   turtle.refuel(1)
			   turtle.select(2)
		    end
		   turtle.down()
	    end
	    print("Finished tree!")
    end
end
function forward()
    turtle.forward()
    if curFacing == 0 then
	    curZ = curZ + 1
    else if curFacing == 1 then
	    curX = CurX - 1
    else if curFacing == 2 then
	    curZ = curZ - 1
    else
	    curX = curX + 1
    end
end
function left()
    turtle.left()
    if curFacing == 0 then
	    curFacing = 3
    else
	    curFacing = curFacing - 1
    end
    saveData()
end
function right()
    turtle.right()
    if curFacing == 3 then
	    curFacing = 0
    else
	    curFacing = curFacing + 1
    end
    saveData()
end
function up()
    turtle.up()
    curY = curY + 1
    saveData()
end
function down()
    turtle.down()
    curY = curY - 1
    saveData()
end
function saveData()
    local file = fs.open("/data", "w")
    file.writeLine(curX)
    file.writeLine(curY)
    file.writeLine(curZ)
    file.writeLine(curFacing)
    file.close()
end
function loadData()
    local file = fs.open("/data", "r")
    curX = file.readLine()
    curY = file.readLine()
    CurZ = file.readLine()
    curFacing = file.readLine()
    if curX == nil then
	    curFacing = 0
	    curX = 0
	    curY = 0
	    curZ = 0
	    print("No save data found!")
    else if curX ~= 0 and curY ~= 0 and curZ ~= 0 then
	    print("Save data loaded!")
	    if curFacing == 0 then
		    curFacingString = "south"
	    else if curFacing == 1 then
		    curFacingString = "west"
	    else if curFacing == 2 then
		    curFacingString = "south"
	    else if curFacing == 3 then
		    curFacingString = "east"
	    end
	    print("I am at X="..curX..", Y="..curY..", Z="..curZ.."and I am facing "..curFacingString..".")
    else
	    print("Save data loaded!")
	    print("I am at my home position")
    end
end
-- Main function
loadData()
NDFJay #2
Posted 29 December 2012 - 03:14 AM
I am basically having a problem with where I place my "end". I am really not to this as I usually program in Java. Any help is appreciated, especially if you can describe a little more what went wrong.



else if curX ~= 0 and curY ~= 0 and curZ ~= 0 then
			print("Save data loaded!")
			if curFacing == 0 then
					curFacingString = "south"
			else if curFacing == 1 then
					curFacingString = "west"
			else if curFacing == 2 then
					curFacingString = "south"
			else if curFacing == 3 then
					curFacingString = "east"


thats the error, its in the loadData function

replace else if with elseif, remove the space between else and if, that should fix it

EDIT – this needs to be done throughout your code where ever you have else is instead of elseif
Frederikam #3
Posted 29 December 2012 - 03:24 AM
I am basically having a problem with where I place my "end". I am really not to this as I usually program in Java. Any help is appreciated, especially if you can describe a little more what went wrong.



else if curX ~= 0 and curY ~= 0 and curZ ~= 0 then
			print("Save data loaded!")
			if curFacing == 0 then
					curFacingString = "south"
			else if curFacing == 1 then
					curFacingString = "west"
			else if curFacing == 2 then
					curFacingString = "south"
			else if curFacing == 3 then
					curFacingString = "east"


thats the error, its in the loadData function

replace else if with elseif, remove the space between else and if, that should fix it

EDIT – this needs to be done throughout your code where ever you have else is instead of elseif

Hmm, i was sure the syntax was "else if" in Lua. Okay thanks.