Search code examples
lualove2d

lua - main.lua:18: 'end' expected (to close 'function' at line 12) near 'elseif'


I'm coming from Java and trying to program iPad applications with lua and love2d. I'm fairly new and I always get this error:

Syntax error: main.lua:18: 'end' expected (to close 'function' at line 12) near 'elseif'

This is my code:

function setup()
i = 0
end

function draw()
if i == 0
then
background(0, 0, 0, 0)
i = i + 1
end
elseif i == 1
then
background(255, 0, 0, 0)
i = i + 1

elseif i == 2
then
background(0, 255, 0, 0)
i = i + 1

elseif i == 3
then
background(0, 0, 255, 0)
i = i + 1

elseif i == 4
then
background(255, 255, 0, 0)
i = i + 1

elseif i == 5
then
background(255, 255, 255, 0)
i = i + 1

elseif i == 6
then
background(0, 255, 255, 0)
i = i + 1

elseif i == 7
then
background(255, 0, 255, 0)
i = 0
end

What is the problem and what do I do to fix it and avoid it in the future? Thanks.


Solution

  • You have if...then...end...elseif.... The "end" doesn't belong there.