"elseif" 附近的语法错误,"end" 附近的语法错误等等。

这是我第一次尝试使用 Lua,所以我完全不熟悉它。 下面的代码部分是其他人的工作,部分是我自己完成的。 我遇到了题目中指出的问题。有人能帮我解决这些错误并检查一下是否还有其他错误吗?非常感谢!

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
点赞
用户5240636
用户5240636

如果您将代码缩进(见下文),则错误位置将变得更清晰。

bloodRound=600
hardRound=700

function main()
    while count<6000 do
        fightEvil();
    end
--> 此行应有“end”

function fightEvil()
    -- snip --
end

注意 function main() 缺少 end 吗?

我建议您获取一个不错的文本编辑器,专门用于编辑代码,它将自动缩进并对关键字进行语法高亮等操作。 我目前正在使用 Sublime Text 2,它有一个 Lua 语法高亮器。 还有 许多其他的编辑器 可供选择。

如果您需要快速学习 Lua 脚本,可以查看 Learn Lua in Y Minutes :)

无论如何,以下是(可能)修复后的代码:

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
2015-08-29 13:38:26