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

eof expected

Started by bobmarley123456, 23 February 2015 - 06:55 PM
bobmarley123456 #1
Posted 23 February 2015 - 07:55 PM
Can someone correct what i've done here and tell me how to avoid it?

function main()
term.clear()
pullEvent = os.pullEventRaw
term.clear()
term.setCursorPos( 1,1)
print "WareHouseOS Alpha 1.1"
sleep(1)
print("Welcome!")
sleep(3)
write("Item: ")
end
end

main()

function searchdirt()
if item == (dirt) then
sleep(1)
print("Item Found")
sleep(1)
print("UA101")

searchdirt()

BTW im relatively new so sorry if this seems really simple
Thanks
Edited on 23 February 2015 - 07:02 PM
Quintuple Agent #2
Posted 23 February 2015 - 08:09 PM
Well, it would be nice if you post the errors you are getting and what you want the code to do, however throwing this into a editor like notepad++ shows some of the problems quickly.
You have an extra end, on line 12, and you don't close out your searchdirt function or the if statement within it, so that needs an end on line 22 and 23, also you can move when you call your functions (not needed but it looks better and helps with editing)
Another thing is that i believe you meant to have os.pullEvent = os.pullEventRaw, however you just have pullEvent = os.pullEventRaw
Another problem is your searchdirt function
the variables 'item' and 'dirt' have not been set, so they will be nil. This means that your if statement will always be true (nil == nil) and "Item Found" will always be printed, I believe you are trying to see if what was entered by the user was the word dirt, however I am not sure.

Spoiler

function main()
term.clear()
os.pullEvent = os.pullEventRaw
term.clear()
term.setCursorPos( 1,1)
print("WareHouseOS Alpha 1.1")
sleep(1)
print("Welcome!")
sleep(3)
write("Item: ")
end --end of main()

function searchdirt()

if item == (dirt) then --This needs to be changed, it will always be true since both variables are nil and nil==nil is true
   sleep(1)
   print("Item Found")
   sleep(1)
   print("UA101")
end --end of if statement

end --end of searchdirt()

main()
searchdirt()

Edit: Added some extra spaces and lines in the code because the editor does not like copying from notepad++
Edited on 23 February 2015 - 07:13 PM
TheOddByte #3
Posted 23 February 2015 - 09:55 PM
eof stands for unexpected end of file, which is happens when you have too many ends.
In this case you've declared an end too many after your function main.

end is needed when you've declared a function, a statement, or a loop

function foo()
	print( "bar" )
end --# End the function we declared

while true do --# An infinite loop
	if 1 == 1 then
		print( "One equals one! :o/>/>" )
		break --# Break out of the loop
	end --# End the statement
end --# End the loop

Note, that if you use if/elseif/else, it only needs one end

if 1 == 2 then
	print( "One equals two? O.o" )
elseif 1 == 1 then
	print( "One equals one! :D/>/>" )
else
	print( "What.. It wasn't equal two any of them?" )
end
So basically it first checks if one is equal to two, which it isn't, it then goes to the next statement and checks if it's equal to one, which it is.
When the statement is true it executes the code in that statement, however, if both of those statements would have been false it would have executed the code in the else statement.

As I've told others before, I'm bad at explaining :P/>
Here, have a look at the PIL, as you're guaranteed to learn something from it.
Edited on 23 February 2015 - 08:56 PM