ExitLoop in If-Abfrage

10/09/2014 19:24 Moneypulation#1
Edit real problem:

Code:
While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
	Case $CheckboxOnOff
	   $On = True
    Case $GUI_EVENT_CLOSE
	   Exit
	Case $AA = 0
	   If GUICtrlRead($CheckboxAA) = $GUI_CHECKED Then
	   WinSetState("MWarTool","",@SW_MINIMIZE)
	   While Sleep(30)
		  ToolTip("Go to the center of your Attack Button and press F2")
		  If _IsPressed(71) Then
			 $mPos = MouseGetPos()
			 $Color = PixelGetColor($mPos[0],$mPos[1])
			 MsgBox(0,"",$AA)
			 $AA = 1
			 ToolTip("")
			 WinSetState("MWarTool","",@SW_RESTORE)
			 MsgBox(0,"",$AA)
			 ExitLoop
		  EndIf
		 WEnd
	   EndIf
	EndSwitch
 WEnd
ExitLoop actually works. The part that is not working is the switch. Although I set $AA to 1 in the If statement, the script it goes again into Case $AA = 0. Why is that so? I declared on the top of the script Global $AA = 0
10/09/2014 20:14 fuso98#2
Quote:
Originally Posted by moneypulation View Post
Hey,

ich versteh einfach nicht wieso ExitLoop keine "Loops" beendet, sondern die If Abfrage, in der sie ist.

Code:
Case $AA = 0
	  If _IsChecked($CheckboxAA) Then
	   WinSetState("MWarTool","",@SW_MINIMIZE)
           While Sleep(30)
                 ToolTip("Go to the center of your Attack Button and press F2")
		  If _IsPressed(71) Then
			 $mPos = MouseGetPos()
			 $Color = PixelGetColor($mPos[0],$mPos[1])
			 MsgBox(0,"",$AA)
			 Global $AA = 1
			 Global $Done = 1
			 ToolTip("")
			 
			 WinSetState("MWarTool","",@SW_RESTORE)
			 MsgBox(0,"",$AA)
			 ExitLoop (1)

		  EndIf
		  
		  If $Done = 1 Then
			 MsgBox(0,"","Test")
			 ExitLoop
		  EndIf

	   WEnd
Das mit dem $Done ist nur ein Test gewesen um zu sehen, ob die Schleife immernoch an ist (Ist nämlich eine While schleife in einer anderen While schleife). Sobald die If bedingung erfüllt wird, werden die Pixel bzw. die Farbe abgespeichert und die While Schleife sollte beendet werden aber ExitLoop bricht nur die If-Abfrage ab (Hab ich getestet) statt die Schleife zu beenden. Und mit ExitLoop (2) beendet er beide While Schleifen und mein Programm beendet sich... Hilfe ?!
If you press F2 the "if..then" that check $done will never be executed! Cause you put an exit loop before the endif.
Exit loop don't work with if...endif but only with while, for and do loop ;)

Maybe i didn't understood your question. Could you try to speak english?
10/09/2014 20:15 alpines#3
Hmm.
Code:
While 1
	If 1=1 Then
		MsgBox(0,0,0)
		ExitLoop
		MsgBox(0,0,1)
	EndIf

	MsgBox(0,0,3)
WEnd

MsgBox(0,0,2)
10/09/2014 20:28 Moneypulation#4
Quote:
Originally Posted by fuso98 View Post
If you press F2 the "if..then" that check $done will never be executed! Cause you put an exit loop before the endif.
Exit loop don't work with if...endif but only with while, for and do loop ;)

Maybe i didn't understood your question. Could you try to speak english?
$Done is only made for test reasons. My problem is that my ExitLoop exits the If statement instead of the while loop.

Quote:
Originally Posted by alpines View Post
Hmm.
Code:
While 1
	If 1=1 Then
		MsgBox(0,0,0)
		ExitLoop
		MsgBox(0,0,1)
	EndIf

	MsgBox(0,0,3)
WEnd

MsgBox(0,0,2)
Ja bei mir geht das irgendwie nicht. Es kommt sozusagen Msgbox 0, dann 3
10/09/2014 20:40 KDeluxe#5
Downloade dir die letzte stabile AutoIt Version (3.3.12.0).
10/09/2014 20:45 Moneypulation#6
Quote:
Originally Posted by KDeluxe View Post
Downloade dir die letzte stabile AutoIt Version (3.3.12.0).
Ist bei mir 3.3.12.0

Okay I found the real problem:

Code:
While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
	Case $CheckboxOnOff
	   $On = True
    Case $GUI_EVENT_CLOSE
	   Exit
	Case $AA = 0
	   If GUICtrlRead($CheckboxAA) = $GUI_CHECKED Then
	   WinSetState("MWarTool","",@SW_MINIMIZE)
	   While Sleep(30)
		  ToolTip("Go to the center of your Attack Button and press F2")
		  If _IsPressed(71) Then
			 $mPos = MouseGetPos()
			 $Color = PixelGetColor($mPos[0],$mPos[1])
			 MsgBox(0,"",$AA)
			 $AA = 1
			 ToolTip("")
			 WinSetState("MWarTool","",@SW_RESTORE)
			 MsgBox(0,"",$AA)
			 ExitLoop
		  EndIf
		 WEnd
	   EndIf
	EndSwitch
 WEnd
ExitLoop actually works. The part that is not working is the switch. Although I set $AA to 1 in the If statement, the script it goes again into Case $AA = 0. Why is that so? I declared on the top of the script Global $AA = 0
10/09/2014 21:19 butter123#7
an der stelle ist $aa=0 eine zuweisung, die true zurück gibt. case wird benutz um eine variable ($nmsg) auf mehrere werte zu überprüfen ($checkboxonof,$guieventclose). also überprüfst du ob $nmsg = true ist. um zu überprüfen ob $aa = 0 ist musst eine neue ifabfrage machen
10/09/2014 21:27 Moneypulation#8
Quote:
Originally Posted by butter123 View Post
an der stelle ist $aa=0 eine zuweisung, die true zurück gibt. case wird benutz um eine variable ($nmsg) auf mehrere werte zu überprüfen ($checkboxonof,$guieventclose). also überprüfst du ob $nmsg = true ist. um zu überprüfen ob $aa = 0 ist musst eine neue ifabfrage machen
Danke für den Tipp. Hab jetzt eine If-Abfrage außerhalb des Switch's und jetzt funktionierts
10/09/2014 21:35 lolkop#9
Quote:
Originally Posted by butter123 View Post
an der stelle ist $aa=0 eine zuweisung, die true zurück gibt.
Fast :P

$aa=0 ist an der stelle eben keine Zuweisung sondern ein Vergleich. Das Ergebnis des Vergleichs wird dann mit dem Wert im Switch-Header verglichen. Stimmen diese überein, so wird der Case ausgeführt.

Code:
$a=1
Switch False
	Case $a=1 ; True != False -> Skip this case!
		ConsoleWrite("0.o"&@CRLF)
	Case Else
		ConsoleWrite("wie erwartet"&@CRLF)
EndSwitch

Switch True
	Case $a=1 ; True == True -> Step into this case!
		ConsoleWrite("wie erwartet"&@CRLF)
	Case Else
		ConsoleWrite("0.o"&@CRLF)
EndSwitch
Semantisch Äquivalent dazu wäre zb:
Code:
$a=1
If False = ($a=1) Then
	ConsoleWrite("0.o"&@CRLF)
Else
	ConsoleWrite("wie erwartet"&@CRLF)
EndIf

If True = ($a=1) Then
	ConsoleWrite("wie erwartet"&@CRLF)
Else
	ConsoleWrite("0.o"&@CRLF)
EndIf
Quote:
Originally Posted by butter123 View Post
um zu überprüfen ob $aa = 0 ist musst eine neue ifabfrage machen
Alternativ könnte man natürlich auch mit Select statt Switch arbeiten. Dort gäbe es keine fixe Variable mit der alles verglichen wird...
10/22/2014 12:25 Lawliet#10
#closed