Timer 一次运行多个函数

Timer 一次运行多个函数,timer,autoit,Timer,Autoit,其目标是为用户创建计时器。它有丛林营地;每一个人在杀死它后都会在一定时间内重生 为此,我想同时为多个定时器激活相同的功能。如果我同时杀死蓝牛和狼,我希望它们都有定时器,点击蓝色傀儡的按钮,我的狼就能得到相同的定时器 我没有实现狼群按钮,但是有一个开始按钮。单击蓝色按钮启动我的计时器,但随后单击开始游戏按钮只是将其排队,直到第一个计时器完成 我调查了一下。但我不想停止计时器的运行;我想同时运行另一个。是否存在编码错误、更好的做事方式等。?这是我的密码: #include <GUIConsta

其目标是为用户创建计时器。它有丛林营地;每一个人在杀死它后都会在一定时间内重生

为此,我想同时为多个定时器激活相同的功能。如果我同时杀死蓝牛和狼,我希望它们都有定时器,点击蓝色傀儡的按钮,我的狼就能得到相同的定时器

我没有实现狼群按钮,但是有一个开始按钮。单击蓝色按钮启动我的计时器,但随后单击开始游戏按钮只是将其排队,直到第一个计时器完成

我调查了一下。但我不想停止计时器的运行;我想同时运行另一个。是否存在编码错误、更好的做事方式等。?这是我的密码:

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <Timers.au3>

;==> Set our $font variable
Global $font
$font = "Arial Black"

;==> Create our Graphic User Interface
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
$mainwindow = GUICreate("Jungle Timers Deluxe", 200, 400)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$startbutton = GUICtrlCreateButton("Start Game", 50, 10, 70)
$ybluebuff = GUICtrlCreateButton("Ancient Golem (Blue)", 10, 40, 50, 50, $BS_MULTILINE)
$yredbuff = GUICtrlCreateButton("Lizard Elder (Red)", 10, 110, 50, 50, $BS_MULTILINE)
$ywraiths = GUICtrlCreateButton("Lizard Elder (Red)", 10, 180, 50, 50, $BS_MULTILINE)
$ywolves = GUICtrlCreateButton("Lizard Elder (Red)", 10, 250, 50, 50, $BS_MULTILINE)
$ydgolems = GUICtrlCreateButton("Lizard Elder (Red)", 10, 320, 50, 50, $BS_MULTILINE)
$ebluebuff = GUICtrlCreateButton("Ancient Golem (Blue)", 100, 40, 50, 50,     $BS_MULTILINE)
$eredbuff = GUICtrlCreateButton("Lizard Elder (Red)", 100, 110, 50, 50, $BS_MULTILINE)
$ewraiths = GUICtrlCreateButton("Lizard Elder (Red)", 100, 180, 50, 50, $BS_MULTILINE)
$ewolves = GUICtrlCreateButton("Lizard Elder (Red)", 100, 250, 50, 50, $BS_MULTILINE)
$edgolems = GUICtrlCreateButton("Lizard Elder (Red)", 100, 320, 50, 50, $BS_MULTILINE)
;==> Create our events
GUICtrlSetOnEvent($startbutton, "StartGame")
GUICtrlSetOnEvent($ybluebuff, "yBlueBuff")
;==> Display our Graphic User Interface.
GUISetState(@SW_SHOW)
While 1
Sleep(1000) ; Idle around
WEnd
Func yBlueBuff()
Dim $bluetimer = 10
$i = 1
$ybb = GUICtrlCreateLabel("Your Blue Buff:", 10, 40)
GUICtrlDelete($ybluebuff)
$ybblabel = GUICtrlCreateLabel($i, 15, 60, 50, 40)
While $i <= $bluetimer
    GUICtrlDelete($ybblabel)
    If $i >= 5 Then
        $ybblabel = GUICtrlCreateLabel($i, 15, 60, 50, 40)
        GUICtrlSetFont(-1, 22, 500, $font)
        GUICtrlSetBkColor($ybblabel, 0xFFCCCC)
        $i = $i + 1
    ElseIf $i < 5 Then
        $ybblabel = GUICtrlCreateLabel($i, 15, 60, 50, 40)
        GUICtrlSetFont(-1, 22, 500, $font)
        $i = $i + 1
    EndIf
    Sleep(1000)
WEnd
GUICtrlDelete($ybblabel)
GUICtrlDelete($ybb)
$ybluebuff = GUICtrlCreateButton("Ancient Golem (Blue)", 10, 40, 50, 50, $BS_MULTILINE)
EndFunc   ;==>yBlueBuff

Func StartGame()
    ; Activate your League Window
    WinActivate("[CLASS:Notepad]")

    ; Wait for the Notepad become active - it is titled "Untitled - Notepad" on English systems
    WinWaitActive("[CLASS:Notepad]")

    ; Now that the Notepad window is active type some text
    Send("{ENTER}Baron spawns in 15, Dragon spawns at 2:30{ENTER}")
    Sleep(500)
    Send("{ENTER}Wraiths/Wolves/Double Golems spawn at 1:40. Red & Blue spawn at 1:55{ENTER}")
    Sleep(500)

EndFunc   ;==>StartGame

Func CLOSEClicked()
    ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE,
    ;and @GUI_WINHANDLE would equal $mainwindow
    MsgBox(0, "GUI Event", "Thanks for using Jungle Timers Deluxe!")
    Exit
EndFunc   ;==>CLOSEClicked

; Finished!
我在示例教程的基础上构建了它,并使用记事本,因为它更易于调试。

AutoIt不支持同时运行两个函数,否则称为多线程

以下是他们的解释:

为了让您的程序工作,您必须能够持续监控按钮是否被按下,同时执行按钮调用的功能

虽然从技术上讲它不是mulithreading,但解决这个问题的一个方法是同时运行多个脚本

有没有。。。更好的做事方式等

演示多个计时器和响应GUI的示例:

#include <GUIConstantsEx.au3>; $GUI_EVENT_CLOSE
#include <Timers.au3>

Global Enum  $TMR_NAME, _
             $TMR_TIME, _
             $TMR_STAMP, _
             $TMR_STATE, _
             $TMR_PROGR, _
             $TMR_BTN, _
             $TMR__ENUM

Global       $g_aTimer[3][$TMR__ENUM]

             $g_aTimer[0][$TMR_NAME] = 'Timer A'
             $g_aTimer[0][$TMR_TIME] = 60
             $g_aTimer[1][$TMR_NAME] = 'Timer B'
             $g_aTimer[1][$TMR_TIME] = 30
             $g_aTimer[2][$TMR_NAME] = 'Timer C'
             $g_aTimer[2][$TMR_TIME] = 10

Main()

Func Main()
    Local $iMsg = 0
    Local $hGui

    GuiMain($hGui, 400, 25)

    While True

        $iMsg = GUIGetMsg()

        Switch $iMsg

            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case Else
                ButtonCheck($iMsg)

        EndSwitch

        TimerUpdate()

    WEnd

    GUIDelete($hGui)
    Exit
EndFunc

Func GuiMain(ByRef $hGui, Const $iWidth, Const $iHeightTimer)
    Local Const $iAmount = UBound($g_aTimer)

    $hGui = GUICreate(@ScriptName, $iWidth, $iHeightTimer * 2 * $iAmount)

    For $i1 = 0 To $iAmount - 1

        $g_aTimer[$i1][$TMR_BTN]   = GUICtrlCreateButton($g_aTimer[$i1][$TMR_NAME], 0, $i1 * ($iHeightTimer * 2), $iWidth / 2, $iHeightTimer)
        $g_aTimer[$i1][$TMR_PROGR] = GUICtrlCreateProgress(0, $iHeightTimer + $i1 * ($iHeightTimer * 2), $iWidth, $iHeightTimer)

    Next

    GUISetState(@SW_SHOW, $hGui)

EndFunc

Func ButtonCheck(Const $iMsg)

    For $i1 = 0 To UBound($g_aTimer) - 1

        If $iMsg = $g_aTimer[$i1][$TMR_BTN] Then

            $g_aTimer[$i1][$TMR_STATE] = True
            $g_aTimer[$i1][$TMR_STAMP] = _Timer_Init()

            ExitLoop

        EndIf

    Next

EndFunc

Func TimerUpdate()
    Local $nDiff

    For $i1 = 0 To UBound($g_aTimer) - 1

        If Not $g_aTimer[$i1][$TMR_STATE] Then ContinueLoop
        $nDiff = _Timer_Diff($g_aTimer[$i1][$TMR_STAMP]) / ($g_aTimer[$i1][$TMR_TIME] * 1000) * 100

        If $nDiff > 100 Then

            $nDiff                     = 100
            $g_aTimer[$i1][$TMR_STATE] = False

        EndIf

        GUICtrlSetData($g_aTimer[$i1][$TMR_PROGR], $nDiff)

    Next

EndFunc

为了让计时器和其他GUI功能正常工作,您需要一个窗口消息处理程序。有关示例,请参阅用户定义的计时器功能类别帮助。