luapico-8

IF ELSE IF END gives Unclosed Function error


I am looking at PICO-8 for the first time.

This simple IF statement give me the error "UNCLOSED FUNCTION AT LINE 1".

function MYTEST() 
  local x = 1
  if x==1 then
    print("x==1")
  else if x==0 then
    print("x==0")
  end
end

I admit the function is of no use but the interpreter won't allow it to run.

Why?


Solution

  • As mentioned in the comments, changing the code from else if to elseif makes it work.

    Alternatively, add an end before the first end:

    function MYTEST() 
      local x = 1
      if x==1 then
        print("x==1")
      else if x==0 then
          print("x==0")
        end
      end
    end