目标是为League of Legends创建计时器。它有丛林营地;每个人在杀死它之后都会重生一段时间。
为此我想同时为多个计时器激活相同的功能。如果我同时杀死蓝色buff和狼,我想要两个定时器(点击我的狼的蓝色魔像按钮来获得相同的计时器)。
我没有实施狼群按钮,但确实有一个开始按钮。单击蓝色按钮启动我的计时器,但点击开始游戏按钮跟进它只是将它排队直到第一个计时器完成后。
我调查了the wiki page。但我不想停止运行计时器;我想同时运行另一个。是否存在编码错误,更好的处理方式等?这是我的代码:
#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!
我在Notepad示例教程中构建了这个并使用记事本,因为它更容易调试。
答案 0 :(得分:3)
AutoIt 不支持同时运行两个函数,也称为多线程。
以下是他们的解释:AutoItNotOnToDoList
为了使您的程序正常工作,您必须能够持续监控按钮是否被按下,同时执行按钮调用的功能。
虽然技术上不是多线程,但此问题的解决方法是同时运行多个脚本。
答案 1 :(得分: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