Posted 26 January 2013 - 11:45 PM
For those who're getting errors in their code I've made a small tutorial that explains why those error occurs, and how you can fix them.
You should also know that Lua is case sensitive.
[namedspoiler=" 'end' expected]
If you're getting this error it means you have forgotten an end.
Take a look at this example
[code]
while true do
if foo == "bar" then
–# code
–# There should be an end here
end
So you simply add an end, it's as simple as that
Now all you have todo is remove that end and your program should run just fine.[namedspoiler=" 'then' expected]
There's multiple cases that can give you this error, I'll show them to you right away
[b]Case 1 : Missing then[/b]
Most of the time this error occurs because you've forgotten to put in 'then'
[code]
if 1 == 1 –# 'then' is missing here
print( "One equals one! :D/>" )
end
Case 2 : Invalid syntax
If you believe you use 'do' for statements you're wrong, they're only used for loops
Case 3 : Invalid statement
This is a common mistake, people often try to compare variables by using '='.
But remember, '=' is for declaring variables, '==' is for comparing
Attempt To Concatenate nil and String
Unfinished String / ')' expected
Attempt To Call nil
String expected, got function
Attempt to call string
Too long without yielding
I hope This Was Any Helpful To Anyone!
You should also know that Lua is case sensitive.
[namedspoiler=" 'end' expected]
If you're getting this error it means you have forgotten an end.
Take a look at this example
[code]
while true do
if foo == "bar" then
–# code
–# There should be an end here
end
So you simply add an end, it's as simple as that
while true do
if foo == "bar" then
--#code
end
end
<eof> expected
eof stands for unexpected end of file or rather end of file expected to be precise, this is caused when you have to many end(s)
function foo()
print( "bar" )
end
end --# How did this get here? Remove it! =P
The code above would error with the error you would expect it to give you.Now all you have todo is remove that end and your program should run just fine.
There's multiple cases that can give you this error, I'll show them to you right away
[b]Case 1 : Missing then[/b]
Most of the time this error occurs because you've forgotten to put in 'then'
[code]
if 1 == 1 –# 'then' is missing here
print( "One equals one! :D/>" )
end
Case 2 : Invalid syntax
If you believe you use 'do' for statements you're wrong, they're only used for loops
if 1 == 1 do --# Change 'do' to 'then'
print( "One equals one! :D/>" )
end
Case 3 : Invalid statement
This is a common mistake, people often try to compare variables by using '='.
But remember, '=' is for declaring variables, '==' is for comparing
if 1 = 1 then --# it should be '==' not '='
print( "One equals one! :D/>" )
end
Attempt To Concatenate nil and String
Spoiler
--Error
print("Hello "..name.."!") -- You'll get this error because
-- You Have not declared "name"
--Solution 1
name = "Homer Simpson"
print("Hello "..name.."!")
-- Here It will print: Hello Homer Simpson!
--Solution 2
write("Enter Your Name:")
name = read()
print("Hello "..name.."!")
--Here It will print Whatever You've Entered
--Like If You've Wrote Jabba Dabba Doo
-- It Will Print That!
Unfinished String / ')' expected
Spoiler
--Error 1
print("Hello) -- Missing the "
--Error 2
print("Hello" -- Missing the ')'
--Solution
print("Hello")
Attempt To Call nil
Spoiler
--Error
explode()
--You Have To Declare What The Function does!
--Solution
function explode()
term.clear()
term.setCursorPos(1,1)
print("BOOM!")
sleep(2)
os.shutdown() -- This Is A Basic In CC , That will Shutdown The Computer!
end -- Remember To Add An End In Your Function!
explode() -- Now You Can Call It Since It Knows
--What To Do When Calling "explode()"
String expected, got function
Spoiler
--Error
test = "Hello"
function test()
write(test)
end
--[[
The Error here is that the function has the same name as the
string and thus you get the error
Solution
Rename the function or string
]]--
test = "Hello"
function hTest()
write(test)
end
or
word = "Hello"
function test()
write(word)
end
Attempt to call string
Spoiler
--Error
function test()
if test == "test" then
print("If this is printed it hasn't errored yet")
end
end
function start()
test = "test"
test()
end
start()
--[[
Solution
It's the same as the SEGF error(String expected, got function)
You have to either rename the function or the string
function test()
if word == "test" then
print("If this is printed it hasn't errored yet")
end
end
function start()
word = "test"
test()
end
start()
or
function hTest()
if test == "test" then
print("If this is printed it hasn't errored yet")
end
end
function start()
test = "test"
hTest()
end
start()
Too long without yielding
Spoiler
--Error
while true do
print("I just got PWND by myself")
end
--[[
You will get this error since you don't yield the loop
at any time, aka paus, This can be fixed by adding sleep(time) to the loop
]]--
--Solution
while true do
print("I just got PWND by myself")
sleep(0) --Since the time is '0' it will automatically take the lowest time that is '0.05' I think
end
I hope This Was Any Helpful To Anyone!
Edited on 23 February 2015 - 09:39 PM