-1

目标是为英雄联盟创建计时器。它有丛林营地;每个人在杀死它后都会重生。

为此,我想同时为多个计时器激活相同的功能。如果我同时杀死蓝色buff和狼,我想要它们的计时器(单击蓝色魔像的按钮让我的狼获得相同的计时器)。

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

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

#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!

我根据记事本示例教程构建了它并使用记事本,因为它更易于调试。

4

2 回答 2

3

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

这是他们的解释: AutoItNotOnToDoList

为了使您的程序正常工作,您必须能够不断地监视按钮是否被按下,同时执行按钮调用的功能。

虽然它在技术上不是多线程,但解决此问题的方法是同时运行多个脚本。

于 2014-10-04T20:09:17.640 回答
0

有没有......更好的做事方式等?

演示多个计时器(和响应式 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
于 2019-03-04T23:04:39.867 回答