Skocz do zawartości
  • 👋 Witaj na MPCForum!

    Przeglądasz forum jako gość, co oznacza, że wiele świetnych funkcji jest jeszcze przed Tobą! 😎

    • Pełny dostęp do działów i ukrytych treści
    • Możliwość pisania i odpowiadania w tematach
    • System prywatnych wiadomości
    • Zbieranie reputacji i rozwijanie swojego profilu
    • Członkostwo w jednej z największych społeczności graczy

    👉 Dołączenie zajmie Ci mniej niż minutę – a zyskasz znacznie więcej!

    Zarejestruj się teraz

[Problem] Zawieszający się button2 - stop.


Rekomendowane odpowiedzi

Opublikowano

Witam.

Posiadam taki oto skrypt:

#NoTrayIcon

#include 
#include 
#include 
#include 
#include 
#include 
#Region ### START Koda GUI section ### Form=C:\Users\Admin\Documents\Final\juz\gra\Nowy folder\Form1.kxf
$Form1 = GUICreate("obot", 441, 348, 249, 219)
$Button1 = GUICtrlCreateButton("Start", 35, 273, 75, 41)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Button2 = GUICtrlCreateButton("Stop", 120, 273, 75, 41)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$updown = GUICtrlCreateCheckbox("Up -> Down", 51, 195, 113, 17)
$leftright = GUICtrlCreateCheckbox("Left -> Right", 51, 220, 113, 25)


GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


$Start = 0



While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $Button1
			$Start = 1

		Case $Button2
			$Start = 0
		EndSwitch

    If GUICtrlRead($updown) == 1 And $Start == 1 Then ;running up down
		ControlSend("Tibia", '', '', '{UP}')
		Sleep(40)
		ControlSend("Tibia", '', '', '{DOWN}')
		Sleep(100)
	EndIf ;==>updown

	If GUICtrlRead($leftright) == 1 And $Start == 1 Then ;running left right
		ControlSend("Tibia", '', '', '{LEFT}')
		Sleep(40)
		ControlSend("Tibia", '', '', '{RIGHT}')
		Sleep(100)
	EndIf ;==>
	Wend

Problem z tym skryptem polega na tym, że by zastopować muszę kliknąć button "stop" dużo razy, gdyż za pierwszym razem nie potrafi zatrybić. Wie ktoś jak to ogarnąć?

 

 

Weteran
Opublikowano

Ja bym wrzucił te pętle do AdlibRegister'a, powinno wtedy działać bez zarzutu.

1329036830-U154499.png
Opublikowano

AutoIt jest jednowątkowy więc możesz zamiast sleep dać timery albo lepiej zamiast funkcji oddzielne programy pracujące w tle i pobierać ich PID i jeżeli jakiś trzeba zamknąć bo np. checkbox jest odznaczony to ProcessClose...

4417049059_6234f40fb5.jpg
Storm has passed but the destruction are still visible.

Opublikowano

 

Witam.

Posiadam taki oto skrypt:

#NoTrayIcon

#include 
#include 
#include 
#include 
#include 
#include 
#Region ### START Koda GUI section ### Form=C:\Users\Admin\Documents\Final\juz\gra\Nowy folder\Form1.kxf
$Form1 = GUICreate("obot", 441, 348, 249, 219)
$Button1 = GUICtrlCreateButton("Start", 35, 273, 75, 41)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Button2 = GUICtrlCreateButton("Stop", 120, 273, 75, 41)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$updown = GUICtrlCreateCheckbox("Up -> Down", 51, 195, 113, 17)
$leftright = GUICtrlCreateCheckbox("Left -> Right", 51, 220, 113, 25)


GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


$Start = 0



While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $Button1
			$Start = 1

		Case $Button2
			$Start = 0
		EndSwitch

    If GUICtrlRead($updown) == 1 And $Start == 1 Then ;running up down
		ControlSend("Tibia", '', '', '{UP}')
		Sleep(40)
		ControlSend("Tibia", '', '', '{DOWN}')
		Sleep(100)
	EndIf ;==>updown

	If GUICtrlRead($leftright) == 1 And $Start == 1 Then ;running left right
		ControlSend("Tibia", '', '', '{LEFT}')
		Sleep(40)
		ControlSend("Tibia", '', '', '{RIGHT}')
		Sleep(100)
	EndIf ;==>
	Wend
Problem z tym skryptem polega na tym, że by zastopować muszę kliknąć button "stop" dużo razy, gdyż za pierwszym razem nie potrafi zatrybić. Wie ktoś jak to ogarnąć?

 

Po co Ci tyle include bez niczego? o.O

9obpmnjr.png

Opublikowano

ten skrypt robiłem na szybko, ale ogólnie jest on częścią mojego pro elo skryptu :D Właśnie z tą rzeczą mam problem. Reszta mi śmiga jak należy.

 

 

Opublikowano

Łap poprawione i ulepszone:

#NoTrayIcon

#include <GUIConstantsEx.au3>

#region ### START
$Form1 = GUICreate("obot", 441, 348, 249, 219)
$Button1 = GUICtrlCreateButton("Start", 35, 273, 75, 41)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Button2 = GUICtrlCreateButton("Stop", 120, 273, 75, 41)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$updown = GUICtrlCreateCheckbox("Up - Down", 51, 195, 113, 17)
$leftright = GUICtrlCreateCheckbox("Left - Right", 51, 220, 113, 25)
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#endregion ### START

$lr = 0
$ud = 0

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE

			If $lr = 1 Then

				AdlibUnRegister("lr")
				$lr = 0

			ElseIf $ud = 1 Then

				AdlibUnRegister("ud")
				$ud = 0

			EndIf

			Exit

		Case $Button1
			
			If $lr = 1 Then

				AdlibUnRegister("lr")
				$lr = 0

			ElseIf $ud = 1 Then

				AdlibUnRegister("ud")
				$ud = 0

			EndIf

			If GUICtrlRead($leftright) = $GUI_CHECKED Then

				AdlibRegister("lr", 100)
				$lr = 1

			ElseIf GUICtrlRead($updown) = $GUI_CHECKED Then

				AdlibRegister("ud", 100)
				$ud = 1

			EndIf

			If ($lr = 0) And ($ud = 0) Then

				MsgBox(16, "obot", "Nic nie wybrano!")

			EndIf


		Case $Button2

			If $lr = 0 And $ud = 0 Then

				MsgBox(16, "obot", "Nie ma czego zatrzymywać!")

			EndIf

			If $lr = 1 Then

				AdlibUnRegister("lr")
				$lr = 0

			ElseIf $ud = 1 Then

				AdlibUnRegister("ud")
				$ud = 0

			EndIf

	EndSwitch

WEnd

Func lr()

	ControlSend("Tibia", '', '', '{LEFT}')
	Sleep(40)
	ControlSend("Tibia", '', '', '{RIGHT}')


EndFunc   ;==>lr

Func ud()

	ControlSend("Tibia", '', '', '{UP}')
	Sleep(40)
	ControlSend("Tibia", '', '', '{DOWN}')

EndFunc   ;==>ud

9obpmnjr.png

Opublikowano

JESTEŚ WIELKI!! Umieściłem to w moim skrypcie i jest... no po prostu piękne :D<3

Dokładnie o takie coś mi chodziło. Szczerze to ja dopiero zaczynam i prawdę mówiąc nie ogarniam takich skryptów. Takie skrypty zaliczam do skomplikowanych. Naprawdę to z niego niewiele rozumiem, ale ważne że działa :D

 

Dzięki wielkie! :D

 

 

Opublikowano
#NoTrayIcon

#include 
#include 
#include 
#include 
#include 
#include 


$Form1 = GUICreate("obot", 441, 348, 249, 219)
$Button1 = GUICtrlCreateButton("Start", 35, 273, 75, 41)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Button2 = GUICtrlCreateButton("Stop", 120, 273, 75, 41)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetOnEvent($Button2, "stopLoop")

$updown = GUICtrlCreateCheckbox("Up -> Down", 51, 195, 113, 17)
$leftright = GUICtrlCreateCheckbox("Left -> Right", 51, 220, 113, 25)
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)


Global $Start = 0

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $Button1
			Global $Start = 1
		Case $Button2
			Global $Start = 0
	EndSwitch

    If GUICtrlRead($updown) == 1 And $Start == 1 Then ;running up down
		ControlSend("Tibia", '', '', '{UP}')
		if iSleep(40) <> 1 Then continueLoop
		ControlSend("Tibia", '', '', '{DOWN}')
		if iSleep(100) <> 1 Then continueLoop
	EndIf ;==>updown

	If GUICtrlRead($leftright) == 1 And $Start == 1 Then ;running left right
		ControlSend("Tibia", '', '', '{LEFT}')
		if iSleep(40) <> 1 Then continueLoop
		ControlSend("Tibia", '', '', '{RIGHT}')
		if iSleep(100) <> 1 Then continueLoop
	EndIf ;==>
Wend
;original: http://www.autoitscript.com/wiki/Interrupting_a_running_function
Func iSleep( $iDelay )
 	Local $iBegin = TimerInit()
 	Do
 		Sleep(10)
		
 		If $Start <> 1 Then Return False
		
 	Until TimerDiff($iBegin) > $iDelay
 	Return True
endFunc

Func stopLoop()
	Global $Start = 0
endFunc

 

O wiele łatwiejsze rozwiązanie.

WSZYSTKIE PLIKI W CHMURZE DLA MPCFORUM ZOSTAŁY USUNIĘTE. NIE KORZYSTAĆ Z MOICH PROGRAMÓW.

Proszę nie ingerować w moje posty/tematy, w razie potrzeby usunąć całą zawartość. Nie pomagam.

Opublikowano

 

#NoTrayIcon

#include 
#include 
#include 
#include 
#include 
#include 


$Form1 = GUICreate("obot", 441, 348, 249, 219)
$Button1 = GUICtrlCreateButton("Start", 35, 273, 75, 41)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Button2 = GUICtrlCreateButton("Stop", 120, 273, 75, 41)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetOnEvent($Button2, "stopLoop")

$updown = GUICtrlCreateCheckbox("Up -> Down", 51, 195, 113, 17)
$leftright = GUICtrlCreateCheckbox("Left -> Right", 51, 220, 113, 25)
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)


Global $Start = 0

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $Button1
			Global $Start = 1
		Case $Button2
			Global $Start = 0
	EndSwitch

    If GUICtrlRead($updown) == 1 And $Start == 1 Then ;running up down
		ControlSend("Tibia", '', '', '{UP}')
		if iSleep(40) <> 1 Then continueLoop
		ControlSend("Tibia", '', '', '{DOWN}')
		if iSleep(100) <> 1 Then continueLoop
	EndIf ;==>updown

	If GUICtrlRead($leftright) == 1 And $Start == 1 Then ;running left right
		ControlSend("Tibia", '', '', '{LEFT}')
		if iSleep(40) <> 1 Then continueLoop
		ControlSend("Tibia", '', '', '{RIGHT}')
		if iSleep(100) <> 1 Then continueLoop
	EndIf ;==>
Wend
;original: http://www.autoitscript.com/wiki/Interrupting_a_running_function
Func iSleep( $iDelay )
 	Local $iBegin = TimerInit()
 	Do
 		Sleep(10)
		
 		If $Start <> 1 Then Return False
		
 	Until TimerDiff($iBegin) > $iDelay
 	Return True
endFunc

Func stopLoop()
	Global $Start = 0
endFunc

 

O wiele łatwiejsze rozwiązanie.

 

A przy okazji ma burdel we While i nie tylko. ;)

 

Dodatkowo popatrz, jakie fragmenty mu dodałem do kodu.

9obpmnjr.png

Opublikowano

Mhm, twoje rozwiązanie jest efektywniejsze, choć jak już masz edytować 3/4 kodu to zablokuj gui zamiast blokować loop.

WSZYSTKIE PLIKI W CHMURZE DLA MPCFORUM ZOSTAŁY USUNIĘTE. NIE KORZYSTAĆ Z MOICH PROGRAMÓW.

Proszę nie ingerować w moje posty/tematy, w razie potrzeby usunąć całą zawartość. Nie pomagam.

Opublikowano

Mhm, twoje rozwiązanie jest efektywniejsze, choć jak już masz edytować 3/4 kodu to zablokuj gui zamiast blokować loop.

 

To nie ma najmniejszego sensu, jeśli on zamierza tam pakować jeszcze nie wiadomo co.

9obpmnjr.png

Opublikowano

#NoTrayIcon

#include <GUIConstantsEx.au3>

#region ### START

$Form1 = GUICreate("obot", 441, 348, 249, 219)

$Button1 = GUICtrlCreateButton("Start", 35, 273, 75, 41)

GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

$Button2 = GUICtrlCreateButton("Stop", 120, 273, 75, 41)

GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

$updown = GUICtrlCreateCheckbox("Up - Down", 51, 195, 113, 17)

$leftright = GUICtrlCreateCheckbox("Left - Right", 51, 220, 113, 25)

GUICtrlCreateTabItem("")

GUISetState(@SW_SHOW)

#endregion ### START

$lr = 0

$ud = 0

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

If $lr = 1 Then

AdlibUnRegister("lr")

$lr = 0

ElseIf $ud = 1 Then

AdlibUnRegister("ud")

$ud = 0

EndIf

Exit

Case $Button1

If $lr = 1 Then

AdlibUnRegister("lr")

$lr = 0

ElseIf $ud = 1 Then

AdlibUnRegister("ud")

$ud = 0

EndIf

If GUICtrlRead($leftright) = $GUI_CHECKED Then

AdlibRegister("lr", 100)

$lr = 1

ElseIf GUICtrlRead($updown) = $GUI_CHECKED Then

AdlibRegister("ud", 100)

$ud = 1

EndIf

If ($lr = 0) And ($ud = 0) Then

MsgBox(16, "obot", "Nic nie wybrano!")

EndIf

Case $Button2

If $lr = 0 And $ud = 0 Then

MsgBox(16, "obot", "Nie ma czego zatrzymywać!")

EndIf

If $lr = 1 Then

AdlibUnRegister("lr")

$lr = 0

ElseIf $ud = 1 Then

AdlibUnRegister("ud")

$ud = 0

EndIf

EndSwitch

WEnd

Func lr()

ControlSend("Tibia", '', '', '{LEFT}')

Sleep(40)

ControlSend("Tibia", '', '', '{RIGHT}')

EndFunc ;==>lr

Func ud()

ControlSend("Tibia", '', '', '{UP}')

Sleep(40)

ControlSend("Tibia", '', '', '{DOWN}')

EndFunc ;==>ud

zauważyłem, że też nie raz.. hmm nie tyle co nie trybi, co załóżmy zaskakuje po 15 sec.

 

 

Zarchiwizowany

Ten temat przebywa obecnie w archiwum. Dodawanie nowych odpowiedzi zostało zablokowane.

×
×
  • Dodaj nową pozycję...