'end' expected (to close 'if' at line 96) near 'else'

.lua:115: 'end' expected (to close 'if' at line 96) near 'else'

`local screenX = 1920 local screenY = 1080

local retreat = 3


local xAxis = 0

local yAxis = 0

local onPoint = false

function nowPixel()

xNow, yNow = GetMousePosition()

yNow = screenY*yNow/65535

xNow = screenX*xNow/65535

xNow = math.floor(xNow)

yNow = math.floor(yNow)

return xNow, yNow

end

function locateMouse(distance)

xNow, yNow = nowPixel()

if xNow >= xAxis then

xDir = -1*distance

else

xDir = distance

end

if yNow >= yAxis then

yDir = 1*distance

else

yDir = distance

end

for i=0,100 do

if math.abs(xNow - xAxis) <= distance*3 or math.abs(yNow - yAxis) <= distance*3 then

break

else

MoveMouseRelative(xDir,yDir)

xNow, yNow = nowPixel()

if xNow >= xAxis then

xDir = -1*distance

else

xDir = distance

end

if yNow >= yAxis then

yDir = -1*distance

else

yDir = distance

end

else

xDir = distance

end`

点赞
用户3520059
用户3520059

你不能有两个 'else' 语句。 你可能需要一个 'else if',否则代码不知道该做什么。 请问自己:在哪种情况下代码必须修改 yDir 和 xDir?

if condition1:
   # do something
else if condition2:
   # do something else
else:
   # do something else
2020-04-18 18:31:34