Kevin
Kevin

Reputation: 1

syntax error near 'elseif', syntax error near 'end', and so on

this is the first time I try lua so I'm totally unfamiliar with it. The code below is partly others' work and partly done by myself. I've encountered questions as the title indicates. Can somebody help me with these errors and check out whether there is any other mistake for me? Thanks a lot!

bloodRound=600
hardRound=700

function main()  
while count<6000 do
fightEvil();
end   

function fightEvil()
count=count+1;

if isColor(40,495,15178484,90) then touchClick(40,495)
end

if isColor(75,410,8094051,90) then touchClick(75,410)
end

if round<=bloodRound then touchClick(110,230)
elseif round<= hardRound then touchClick(110,420)
else
touchClick(110,570)
end

if isColor(250,550,15721389,90) then touchClick(250,550)

elseif isColor(250,550,14044457,90) then touchClick(250,550)

elseif isColor(250,420,14570908,90) then touchClick(250,420)

elseif isColor(250,420,10251594,90) then touchClick(600,950)

elseif isColor(250,550,2202276,90) then touchClick(250,550)

elseif isColor(250,420,16769965,90) then touchClick(250,420)

elseif isColor(250,250,15716004,90) then touchClick(250,250)

elseif isColor(250,250,15720365,90) then touchClick(250,250)

elseif isColor(250,250,15721397,90) then touchClick(250,250)

elseif isColor(250,250,1656122,90) then touchClick(250,250)

elseif isColor(250,250,14593160,90) then touchClick(250,250)
end
end 

Upvotes: 0

Views: 3062

Answers (1)

cabbageforall
cabbageforall

Reputation: 660

The location of errors will become clearer if you indent your code (see below).

bloodRound=600
hardRound=700

function main()  
    while count<6000 do
        fightEvil();
    end   
--> there should be an `end` on this line

function fightEvil()
    -- snip --
end

Notice the missing end on function main()?

I'd recommend getting a decent text editor, one specifically designed for editing code, as that will do things like auto-indent and also syntax highlight keywords, etc. I'm currently using Sublime Text 2 which has a Lua syntax highlighter. There are many others to choose from.

For a crash course on Lua scripting, check out Learn Lua in Y Minutes :)

Anyway, here is (probably) fixed code:

local bloodRound, hardRound = 600, 700

function main()  
    while count<6000 do
        fightEvil();
    end
end

function fightEvil()
    count=count+1;

    if isColor(40,495,15178484,90) then
        touchClick(40,495)
    end

    if isColor(75,410,8094051,90) then
        touchClick(75,410)
    end

    if round <= bloodRound then
        touchClick(110,230)
    elseif round <= hardRound then
        touchClick(110,420)
    else
        touchClick(110,570)
    end

    if isColor(250,550,15721389,90) then
        touchClick(250,550)

    elseif isColor(250,550,14044457,90) then
        touchClick(250,550)

    elseif isColor(250,420,14570908,90) then
        touchClick(250,420)

    elseif isColor(250,420,10251594,90) then
        touchClick(600,950)

    elseif isColor(250,550,2202276,90) then
        touchClick(250,550)

    elseif isColor(250,420,16769965,90) then
        touchClick(250,420)

    elseif isColor(250,250,15716004,90) then
        touchClick(250,250)

    elseif isColor(250,250,15720365,90) then
        touchClick(250,250)

    elseif isColor(250,250,15721397,90) then
        touchClick(250,250)

    elseif isColor(250,250,1656122,90) then
        touchClick(250,250)

    elseif isColor(250,250,14593160,90) then
        touchClick(250,250)

    end
end 

Upvotes: 1

Related Questions