一次运行多个功能



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

为此,我想同时激活多个计时器的相同功能。如果我同时杀死了蓝色的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!

我从记事本示例教程中构建了此事并使用记事本,因为它更容易调试。

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

这是他们的解释:autoitnotontodolist

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

尽管从技术上讲不是误导,但此问题的解决方法同时运行了多个脚本。

是否有...做事的更好的方法,等等?

示例演示多个计时器(和响应性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

相关内容

  • 没有找到相关文章

最新更新