Threading - ImageSearch

12/20/2015 15:16 Shishidump#1
Hey!!

Ich wollte mal fragen wie ich Folgendes Script so optimieren kann, dass das Script normal
weiter läuft und nicht durch die Sleep Funktion angehalten wird..


Ich komme mit der Funktion von dem Timer nicht so ganz klar..

Ich hoffe ihr wisst was ich meine und vielen dank schonmal. :)
12/20/2015 15:28 Daifoku#2
Die Sleeps entfernen ? o.O

Richtiges Threading gibt es in Autoit nicht und adlib ist hier auch keine Option.

Wenn du eine Aktion verzögern und das Script dabei nicht blockieren willst, solltest du einen Timer verwenden.

Pseudo Code
Code:
while
if(Bedingung) {
  Aktion 1
  Starte Timer1
}
if(Timer1){
  if timeDiff(Timer1) > Zeitschranke {
    doAction1
    delete Timer1
  }
}
Wend
12/20/2015 16:08 loop88#3
wiederholt die suche bis sie nicht mehr wahr ist

Quote:
Do
$result = _Imagesearch(@ScriptDir & "/img/lot.bmp", 1, $x1, $y1, 10)
If $result = 1 Then
Dim $MouseNow = MouseGetPos()
MouseClick("Left", $x1, $y1, 5)
MouseMove($MouseNow[0], $MouseNow[1])
EndIf
Until $result = 0
12/20/2015 16:41 elmarcia#4
Try with timer diff that should be enough
Code:
Global $timer1,$timer2,$ready1,$ready2
$ready1 = 1
$ready2 = 1
Func Lot()

	Dim $x1, $y1

	$result = _Imagesearch(@ScriptDir & "/img/lot.bmp", 1, $x1, $y1, 10)
	If $result = 1 And $ready1 Then
		Dim $MouseNow = MouseGetPos()
		MouseClick("Left", $x1, $y1, 5)
		MouseMove($MouseNow[0], $MouseNow[1])
		$timer1 = TimerInit()
		$ready1 = 0
	EndIf

	$result = _Imagesearch(@ScriptDir & "/img/Free.bmp", 1, $x2, $y2, 10)
	If $result = 1 and $ready2 Then
	Dim $MouseNow1 = MouseGetPos()
		MouseClick("Left", $x2, $y2, 5)
		MouseMove($MouseNow1[0], $MouseNow1[1])
	
	$timer2 = TimerInit()
	$ready2 = 0
	EndIf

If TimerDiff($timer1) >= 200 Then ;200 ms
	$timer1 = Null
	$ready1 = 1
EndIf


If TimerDiff($timer2) >= 200 Then ;200 ms
	$timer2 = Null
	$ready2 = 1
EndIf

	If PixelGetColor(1158, 42) = Dec("563D2C") and $ready4 Then
		MouseClick("Left", 1090, 264, 2)
		Sleep(600)
	      MouseClick("Left", 1151, 265, 2)
	      Sleep(500)
	EndIf

EndFunc
12/20/2015 23:37 Daifoku#5
Quote:
Originally Posted by elmarcia View Post
Try with timer diff that should be enough
wow.
Your "Example" is really bad. Don't post codes if you don't know how to work with autoit. There are so many errors and all in all it's just wrong and not working.