Missing END

Posted by tobiassjosten on Thu 28 Apr 2005 02:15 PM — 3 posts, 18,226 views.

Sweden #0
I wrote this function:
function canEat ()
    if bHerb == 1 then
        if doHerb == nil then
            if aff['anorexia'] ~= 2 then
                return 1
            else
                return 0
            end
        else
            return 0
	end
    else
        return 0
    end
end

And now I'm trying to compare it: canEat () ~= nil
But it just wont work with me. The error message I got speaks of a missing END, to mark the end of the function:
[string "Plugin"]:284: `end' expected (to close `function' at line 237) near `<eof>'

Even though I fail to see how/where the function is lacking a END, I added on in the end, but got this:
[string "Plugin"]:239: attempt to call global `canEat' (a nil value)
stack traceback:
	[string "Plugin"]:239: in function `curePrompt'

I'm guessing there really should be one more END in there, but obviously not in the end of it.. Could anyone with keener LUA-eyes help me out here?
USA #1
You sure that it's this function? Since I don't get an error. Possibly an error where you're calling it? or maybe the function before it?

You can also get rid of all those else's and rewrite it like this (unless of course, you were going to change some of those return 0s later):
function canEat ()
  if bHerb == 1 then
    if doHerb == nil then
      if aff['anorexia'] ~= 2 then
        return 1
      end
    end
  end
  return 0
end
Amended on Thu 28 Apr 2005 05:55 PM by Flannel
Sweden #2
Solved it just now. Apparently I had done something like:
if expression then
    command
if expression2 then
    command2
end

Changed number two to "elseif" and now it's running again.