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

bios:339 "end" expected, line doesnt have anything to do with error?!?!?

Started by Lua.is.the.best, 20 March 2014 - 08:53 PM
Lua.is.the.best #1
Posted 20 March 2014 - 09:53 PM
Sorry if this is the wrong category but I was only on here for 2 days :P/>
This is the message I get when I run my New Revolution Calculator (wont release it until I iron the bug"s" out):
bios:339: [string "NewRev-Calc-01"]:32: 'end' expected (to close 'function' at line 27)
This is bios.lua line 339:
local func, err = loadstring( file.readAll(), fs.getName( _sFile ) )
And the function that does this:


loadfile = function( _sFile )
local file = fs.open( _sFile, "r" )
if file then
local func, err = loadstring( file.readAll(), fs.getName( _sFile ) )
file.close()
return func, err
end
return nil, "File not found"
end

Seems to be something related to ComputerCraft fs api, seeing all those "fs".
What do I do?
Edit 1: Adding code..
Edited on 20 March 2014 - 09:40 PM
SuicidalSTDz #2
Posted 20 March 2014 - 10:32 PM
The error is actually on line 32 of your program. You don't seem to be closing a function started on line 27.
Lua.is.the.best #3
Posted 20 March 2014 - 11:04 PM
I have an "end" on line 32.. TANUB?
SuicidalSTDz #4
Posted 20 March 2014 - 11:45 PM
But if you have nested 'if' statements within your function then you could have missed an 'end' somewhere. It would be better if you could post the script.

This is more or less what I am trying to say:


local function foo()
  if not Cloudy.isAwesome then
    error( "What world do you live in?" )
  end
It is easy to tell that we are missing something here. However, if indentation is not used, like below, it can be easy to lose track of where statements and functions end.


local function foo()
if not Cloudy.isAwesome then
error( "What world do you live in?" )
end

This becomes especially true when you get larger and larger files to work with (i.e. over 100 lines)
Edited on 20 March 2014 - 11:27 PM
oeed #5
Posted 21 March 2014 - 02:00 AM
Post your code, that will help us solve your issue much quicker.
Lua.is.the.best #6
Posted 31 March 2014 - 02:51 AM
OH, there was an if in Calc().
Tried it, but NOTHING POPPED UP.


--some unimportant stuff
local showHelp=0 --Set this to 1 if you are new to the program "THIS was what the if referred to"
--string stuff for Help and the Help function here
function Calc()
print("Currently WIp.")
if showHelp==1 then Help()
elseif showHelp==0 then Calc()
else print("Invalid showHelp value. Change your showHelp value in line 7.")
end
end --Extra end I added to fix the problem
I removed some parts because I thought there were useless for support..
Edited on 31 March 2014 - 02:56 AM
briman0094 #7
Posted 31 March 2014 - 05:55 AM
if showHelp is 0, it will infinitely recurse because Calc() is calling Calc():


elseif showHelp == 0 then Calc()

post your entire script though if you expect reasonable help.
Bomb Bloke #8
Posted 31 March 2014 - 08:39 AM
When you've missed an "end" statement, the Lua VM can only guess as to which bit of code it was supposed to be paired with. It makes an educated guess, but ultimately there may not be enough clues in your code for that guess to be accurate.

Generally, this type of problem can be easily avoided through the use of proper indentation.
RoD #9
Posted 31 March 2014 - 11:50 AM
if you post your whole code we may help you. We can't tell where you missed an "end" statement with a fraction of your code. You shold try to see from line 32 to the end of your code where is a end missing, maybe line 32 is a function or something that is not closed.
Lua.is.the.best #10
Posted 02 April 2014 - 05:18 AM
O.O the strings for Help are not even useful..
OK, I have to change it to like a message. I choose Help is not enabled. Skipping help section.
But I would store it in a variable.
And now I see why it won't run..
It is supposed to print Too long without yielding and stuff.. But it doesnt do it :P/>