定时器循环抛出异常

问题描述 投票:0回答:1

Error screenshot

我的自动化游戏 Vikings 脚本正在执行循环中的第一步(拖动),但在单击事件时抛出上面的错误(这会停止脚本):

HotKeySet("{ESC}", "Terminate")
Func Terminate() ;This function forces the script to stop when you hit the escape key in the top left corner of your keyboard
    MsgBox(0, 'Ending', 'Macro Ended')
    Exit
EndFunc

;Activate your game window
WinActivate("Vikings")
Sleep(200)

;Looping thru 120 minutes
$Minutes = 120
Local $60Count = 0, $begin = TimerInit(), $popup = 1
While $Minutes > $60Count

    $dif = TimerDiff($begin)
    $dif2 = StringLeft($dif, StringInStr($dif, ".") - 1)
    $Count = Int($dif / 1000)
    $60Count = Int($Count / 60)

    ;Selecting Max RRS Food
    Sleep(Random(800, 1200, 1))
    MouseClickDrag("left", 784, 297, 992, 298, 500)
    Sleep(Random(800, 1200, 1))
    ;send
    MouseClick("left", [1156, 793, [1, [3]]])

    ;Selecting Max RRS Lumber
    Sleep(Random(800, 1200, 1))
    MouseClickDrag("left", 784, 381, 989, 381)
    Sleep(Random(800, 1200, 1))
    ;send
    MouseClick("left", [1156, 793, [1, [3]]])

    ;Selecting Max RRS Iron
    Sleep(Random(800, 1200, 1))
    MouseClickDrag("left", 781, 467, 988, 464, 500)
    Sleep(Random(800, 1200, 1))
    ;send
    MouseClick("left", [1156, 793, [1, [3]]])

    ;Selecting Max RRS Stone
    Sleep(Random(800, 1200, 1))
    MouseClickDrag("left", 781, 548, 988, 548, 500)
    Sleep(Random(800, 1200, 1))
    ;send
    MouseClick("left", [1156, 793, [1, [3]]])

    ;Selecting Max RRS Silver
    Sleep(Random(800, 1200, 1))
    MouseClickDrag("left", 781, 631, 988, 633, 500)
    Sleep(Random(800, 1200, 1))
    ;send
    MouseClick("left", [1156, 793, [1, [3]]])
WEnd

MsgBox(64, "Time-Up!!", "Your " & $Minutes & " minutes have passed    ")

我更改了代码:

$iBegin = TimerInit()

While TimerDiff($iBegin) < whatever_delay_you_want
    Your_Code
WEnd

但是没有成功。

autoit
1个回答
0
投票

我认为您可能误解了 MouseClick 的文档。 其中显示

MouseClick ( "button" [, x, y [, clicks = 1 [, speed = 10]]] )
的方括号
[]
表示可选参数。 请参阅“可选参数”部分下的功能说明。基本上你不应该在代码中包含方括号。

此外,我建议在 autoit(SciTE 脚本编辑器)附带的编辑器中测试运行代码,因为它会准确地告诉您代码中的错误所在。

我真的很惊讶这会编译成exe...

© www.soinside.com 2019 - 2024. All rights reserved.