19 posts
Posted 14 June 2012 - 08:22 AM
Right, so I"m learning to code and this is just about to make me give up it's giving me so much frustration.
Eof expected? Right so end of function. So it's saying there needs to be an end to my function? But there is one?
E.g. (wrote this simple as hell program to demonstrate what I'm talking about)
Btw I'm still not sure how to colour the text and put it in that box so its easier to read like everyone else so I'm just gonna have to put a wall of text :L.
func = shaft()
if turtle.detectdown(7)
then
end
ekse
turtle.digdown()
shaft()
end
So I know that the problem is with my ends. Also, I really would prefer being shown how to do ends properly rather than just being corrected Thanks in advance!
992 posts
Posted 14 June 2012 - 09:06 AM
I need the code you are working on before I can find the problem.
Question
do you edit in CC or outside of it with some other IDE / text editor ?? I personally use notepad++
445 posts
Posted 14 June 2012 - 12:35 PM
You have "ekse" there, needs to be "else"
and iirc it was case senstiive so digDown not digdown
besides that script does not make sense?
Looks like you're trying recursion, might be better to use a loop though
992 posts
Posted 14 June 2012 - 12:57 PM
You have "ekse" there, needs to be "else"
and iirc it was case senstiive so digDown not digdown
besides that script does not make sense?
Looks like you're trying recursion, might be better to use a loop though
E.g. (wrote this simple as hell program to demonstrate what I'm talking about)
this is not the code he is working on fixing it will not be useful. is why i asked for the actual code so i can find where the missing "end" is or miss placed "end"
[EDIT]
–response to bellow post–
thank you Pinkishu for reminding me I accidentally confused EOF with END error's
[/EDIT]
445 posts
Posted 14 June 2012 - 02:33 PM
Eof expected actually means theres an end too much, it expects the end of the file but theres another end it cannot link up to something
detectDown(7) doesn't make much sense to me either or is it of any use to put the 7 there?
lets use "scope levels"
func = shaft() -- Scope Level 0
if turtle.detectdown(7) -- Scope Level 0
then -- Scope Level 0->1
end -- Scope Level 1->0
ekse -- fail (lets assume its else) Scope Level 0->1 (notice, theres no if to even link up to since it ended there ^)
turtle.digdown() -- Scope Level 1
shaft() -- Scope Level 1
end - Scope Level 0
So it expects EOF instead of an else since there no if to link it too since it ended the line before
1604 posts
Posted 14 June 2012 - 05:48 PM
The problem is the function definition is wrong, it should be like:
function <FunctionName>()
-- code
end
-- or
<FunctionName> = function()
-- code
end
992 posts
Posted 14 June 2012 - 05:56 PM
The problem is the function definition is wrong, it should be like:
function <FunctionName>()
-- code
end
-- or
<FunctionName> = function()
-- code
end
facepalm
No one is reading the above text. it is Pseudo code that does nothing. To fix the problem he would need to post his ACTUAL CODE.
1604 posts
Posted 14 June 2012 - 06:02 PM
The problem is the function definition is wrong, it should be like:
function <FunctionName>()
-- code
end
-- or
<FunctionName> = function()
-- code
end
facepalm
No one is reading the above text. it is Pseudo code that does nothing. To fix the problem he would need to post his ACTUAL CODE.
And did you read it?
E.g. (wrote this simple as hell program to demonstrate what I'm talking about)
Where does it say it's pseudo-code?
Right so end of function. So it's saying there needs to be an end to my function? But there is one?
If he is really trying to declare functions like that, that's the problem.
But yes, he has to post the actual code so we can see the error.
992 posts
Posted 14 June 2012 - 06:09 PM
the problem he is having is a "Eof expected" error there is no "Eof expected" error in the code he posted (yes there are other problems with it)
the code he posted is a example of a problem cant be fixed from the example code he posted. the func is just lazy doing it in a pseudo way in a demonstration. I would put money on it that in his code he uses the correct "function = exampleName()" syntax
1604 posts
Posted 14 June 2012 - 06:19 PM
the problem he is having is a "Eof expected" error there is no "Eof expected" error in the code he posted (yes there are other problems with it)
Really?
func = shaft() -- attempt to call nil
if turtle.detectdown(7)
then
end
ekse -- = expected (or something else)
turtle.digdown() -- attempt to call nil
shaft() -- attempt to call nil
end -- EOF Expected
The first errors don't matter, since they would never get executed, but the "eof expected" is there.
992 posts
Posted 14 June 2012 - 06:28 PM
there is one pseudo function deceleration and an matching end for it and one if statement with a end for it. there is the correct number of ends to match meaning no "Eof expected" error.
pseudo code is not designed to be executed but for ruffing out a programs flow of command's allowing for change in design before a single real section of code is ever typed. his code is ether a total fail or pseudo code (where func represents a function call and shaft() represents a function that would be called that digs or interacts with a shaft of some kind.)
445 posts
Posted 14 June 2012 - 06:37 PM
well the problem is that the if ends and then he tries to do an else
try it :(/>/>
8543 posts
Posted 14 June 2012 - 06:37 PM
Yes, pseudo code. We get it. You're not understanding that if the function declaration he's using there is the way he's declaring the function in the actual code, that's a problem. Of course we need to see the actual code, but if we are asked to debug based on pseudo code, you don't just blatantly make assumptions that the actual code is more correct than the pseudo code. You especially don't pick and choose which elements to assume they got correct in the actual code.
445 posts
Posted 14 June 2012 - 06:40 PM
Well he says he wrote this program… so it might be real code that he just typed from ingame and typo'ed else? :(/>/>
8543 posts
Posted 14 June 2012 - 06:49 PM
Well he says he wrote this program… so it might be real code that he just typed from ingame and typo'ed else? :(/>/>
I wasn't originally replying to you, by the way. You snuck that post in whilst I was typing!
That bit of code up there has deeper issues than a typo'd else or a broken function declaration. It lacks understanding of if structures, for one thing.
I'd bet the EOF error is more related to the overuse of ends inside ifs than anything else (despite the fact that this one would match up fine if the function declaration was valid). I assume there are enough mismatched ifs and not enough missing ends elsewhere so that we are reaching an end after the closing end.
992 posts
Posted 14 June 2012 - 06:51 PM
I concede on all fronts. His code is complete fail
445 posts
Posted 14 June 2012 - 06:51 PM
Uhm this one would not be fine at all? lol
if then end else will never work :(/>/> unless there was another if above it maybe
8543 posts
Posted 14 June 2012 - 06:57 PM
Uhm this one would not be fine at all? lol
if then end else will never work :(/>/> unless there was another if above it maybe
Heh. Who said it was fine?
19 posts
Posted 15 June 2012 - 04:25 AM
Ok, right lot of stuff to reply to.
Firstly, the reason i typed that instead of my actual code id that I get that sort of error with a lot of things i try to code. If somebody just corrects my code, that only fixes one problem, and one code. What i was really asking for was how do I use 'end' properly. It's a real killer for any coding I attempt. And yes, agreed the code I posted was complete crap, I know that and I have made much better codes, but the best I can do is sustitute from someone else's code because i can't change some things because of 'eof expected'. Basically I would like to either be taught when and how 'end' should be used or pointed to somewhere that can show me how. And yes, I was just being lazy there and typo'd/typed incorrect synatx. I ahve tried many, many different ways of arranging my ends but none seem to work.
445 posts
Posted 15 June 2012 - 10:18 AM
Then correct that code?
8543 posts
Posted 15 June 2012 - 06:11 PM
Please post real code that's actually generating errors in the future. The end statement ends a block of code:
function name()
--code
end
while true do
--code
end
for i=1,42 do
--code
end
if x then
--code
end
if x then
--code
else
--code
end
if x then
--code
elseif y then
--code
else
--code
end
The general rule of thumb is, every function, for, while and if needs a matching end. Note that the entire if/elseif/else block is between the if and its matching end.
19 posts
Posted 16 June 2012 - 07:30 AM
Ok, will try thanks, sorry for not posting the right code.
19 posts
Posted 16 June 2012 - 08:26 AM
Ok, right so, I've followed what you said and fixed up a program I wrote, but now it just runs straight through, without doin a thing, presumably it's somehow hitting an end before it does anything but I don't see how. Could someone please help?
function turtlecom()
shell.run("clear")
print ("Turtlecom Running.")
print ("Write 'help' for help or 'exit' to exit")
x = io.read()
if x == "help" then
print ("f = move forward")
print ("b = move back")
print ("l = turn left")
print ("r = turn right")
print ("Will return to Turtlecom interface in 5 seconds")
sleep(5)
turtlecom()
elseif x == "f" then
turtle.forward()
turtlecom()
elseif x == "b" then
turtle.back()
turtlecom()
elseif x == "l" then
turtle.turnLeft()
turtlecom()
elseif x == "r" then
turtle.turnRight()
turtlecom()
elseif x == "exit" then
print ("Closing turtlecom ...")
sleep(1)
else
print ("That is not a valid command.")
turtlecom()
end
end
Nevermind got it myself. But i would like to know how the os.pullevent() works so i can use it to improve my program (so it's key presses rather than key press and then enter.)
8543 posts
Posted 16 June 2012 - 09:43 AM
By the way, it's very bad practice to call a function from itself in order to create an infinite loop. Use this instead:
while true do
term.clear()
term.setCursorPos(1,1)
print ("Turtlecom Running.")
print ("Write 'help' for help or 'exit' to exit")
x = read()
if x == "help" then
print ("f = move forward")
print ("b = move back")
print ("l = turn left")
print ("r = turn right")
print ("Will return to Turtlecom interface in 5 seconds")
sleep(5)
elseif x == "f" then
turtle.forward()
elseif x == "b" then
turtle.back()
elseif x == "l" then
turtle.turnLeft()
elseif x == "r" then
turtle.turnRight()
elseif x == "exit" then
print ("Closing turtlecom ...")
sleep(1)
break
else
print ("That is not a valid command.")
end
end
19 posts
Posted 16 June 2012 - 09:57 AM
By the way, it's very bad practice to call a function from itself in order to create an infinite loop. Use this instead:
while true do
term.clear()
term.setCursorPos(1,1)
print ("Turtlecom Running.")
print ("Write 'help' for help or 'exit' to exit")
x = read()
if x == "help" then
print ("f = move forward")
print ("b = move back")
print ("l = turn left")
print ("r = turn right")
print ("Will return to Turtlecom interface in 5 seconds")
sleep(5)
elseif x == "f" then
turtle.forward()
elseif x == "b" then
turtle.back()
elseif x == "l" then
turtle.turnLeft()
elseif x == "r" then
turtle.turnRight()
elseif x == "exit" then
print ("Closing turtlecom ...")
sleep(1)
break
else
print ("That is not a valid command.")
end
end
Thanks for the hint. That's much easier to code! I knew of the 'while true do' but never thought of using it like that for some reason.
Also what is the diff between io.read() and read()? or is there none?
Also still looking for an answer to the os.pullevent() question (2 posts up from here)
There are many more features I want to add to this program but the amount of them clogs up the help screen and I need a "next" button. Also, it would be immensly helpful so I don;t have to press enter after every command.
19 posts
Posted 17 June 2012 - 01:23 AM
Might create a new thread for the os.pull as this one seems to have died…
445 posts
Posted 17 June 2012 - 11:31 AM
1 posts
Posted 21 January 2013 - 02:10 AM
I have the same problem on the string: else . I don't know whats that -_-/>
8543 posts
Posted 21 January 2013 - 05:31 AM
I have the same problem on the string: else . I don't know whats that -_-/>
Please create a new topic with the code you're using and the full error message you're receiving.
Locked.