IF ELSE IF END gives Unclosed Function error

2.3k views Asked by At

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?

1

There are 1 answers

1
lhf On BEST ANSWER

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