need help to change script Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Guest

need help to change script

10 Feb 2015, 22:02

i wrote this script but i was told it didn't work because gosub can't be used to exit loops. i am noob and i'm not sure how to write it another way. if someone could help me to change this to make it work that would be great. there is one thing i didn't add also which i would like to. that is the ability to cancel it at any time by pressing F2. here's my code.

Code: Select all

color1 =
color2 =
color3 =
color4 =
color5 = 
color6 =
color7 =

F1::    
PixelGetColor, color1, 410, 561, Alt                      ; press f1 to check to start or not
if (color1 = 0x0000CB)                                       ; if should start go to next step
    break
	Label1:
    Loop,       
    {
        PixelGetColor, color1, 410, 561, Alt              ; press f1 to check to start or not
        if (color1 = 0x0000CB)                               ; if should start
        {
            Click 670, 300                                       ; click find game 
            break
        }
        Sleep, 1000 
    }
    Label2: 
    Loop,       
    {
        PixelGetColor, color2, 780, 430, Alt              ; check for game ready button
        if (color2 = 0x1F1B1A)                               ; if game ready button found
        {
            Click 780, 430                                       ; click accept game button
            break
        }
        Sleep, 1000
    }
    Loop,       
    {
        PixelGetColor, color3, 1600, 900, Alt             ; check for loaded into game
        PixelGetColor, color4, 502, 390, Alt              ; check for returned to finding game
		if (color3 = 0x422410)                       ; if loaded into game
        {
            break                                                  ; go to next step
        }
        else if (color4 = 0xBBBBBB)                       ; otherwise if returned to finding game
		{ 
		    Gosub, Label2                               ; go back to checking for game ready button (label2)
		}
        Sleep, 1000
    }
	 Loop,       
    {
        PixelGetColor, color5, 200, 102, Alt              ; check for being on team 1
        PixelGetColor, color6, 1275, 102, Alt             ; check for being on team 2 
		if (color5 = 0x00FB00)                       ; if on team 1
        {
		    Click 382, 775                               ; select character
		    Sleep, 1000                                  ; wait 1 second
			Click 1100, 775			      ; start game
            break                                                  ; go to next step   
        }
		else if (color6 = 0x0000FB)                 ; otherwise if on team 2
		{ 
		    Click 382, 775                               ; select character
		    Sleep, 1000                                  ; wait 1 second
			Click 1100, 775			      ; start game
			Gosub, Label3                           ; go to team 2 step (label3)
		}
        Sleep, 1000 
    }
	 Loop,       
    {                                                                 ; team 1
        PixelGetColor, color7, 1390, 680, Alt	       ; check for game over	      
        if (color7 != 0x232121)                               ; if game over not found  
        {
            Click right 275, 825			               ; right click a location
        }
		else if (color7 = 0x232121)                  ; otherwise if game over found
		{ 
		   Click right 1390, 680                        ; click exit game button
		   Gosub, Label1                                 ; go to start of script (label1)                                                                  
		}
        Sleep, 1000 
    }
	 Label3:
	 Loop,       
    {                                                                ; team 2
        PixelGetColor, color7, 1390, 680, Alt             ; check for game over
        if (color != 0x232121)   		              ; if game over not found
        {
            Click right 25, 1060                                ; right click a location
        }
		else if (color6 = 0x232121)                 ; otherwise if game over found
		{ 
		    Click right 1390, 680                      ; click exit game button
		    Gosub, Label1                               ; go to start of script (label1)
		}
        Sleep, 1000 
    }
return
User avatar
boiler
Posts: 2653
Joined: 21 Dec 2014, 02:44

Re: need help to change script

11 Feb 2015, 00:27

There are other issues as well. Your if statement is follow by a break, which is used for breaking out of loops. When you see it used after an if statement, it is when the if statement is inside of a loop. I'm guessing that your intent is to not continue if the condition is met, so you want to return instead of break.

You were told correctly that Gosub doesn't exit the loop, it would return to the same spot and continue the loop after it executes the subroutine (but your labels aren't defining subroutines, so it will never come back, so who knows?). It looks like you are wanting to use Goto to jump to your labels.

In general, it's best not to jump around using Goto. There should be a way to accomplish what you want with subroutines (which are defined by a label, some code, then a return). But you might try these changes and see if it works.

To cancel at any time, you mean exit the script? Just add F2::ExitApp at the bottom of your script.
Guest

Re: need help to change script

11 Feb 2015, 00:53

well i'm not sure how that break got there it's not in my code. anyway are you saying i can just replace gosub with goto and it would work properly? heres my code again after i changed it with your suggestion i think. also i want f2 to just stop the script (meaning i have to press f1 to start it again) but not actually close the script.

Code: Select all

color1 =
color2 =
color3 =
color4 =
color5 = 
color6 =
color7 =

F1::    
PixelGetColor, color1, 410, 561, Alt                      ; press f1 to check to start or not
if (color1 = 0x0000CB)                                    ; if should start go to next step
    Label1:
    Loop,       
    {
        PixelGetColor, color1, 410, 561, Alt              ; press f1 to check to start or not
        if (color1 = 0x0000CB)                            ; if should start
        {
            Click 670, 300                                ; click find game 
            break
        }
        Sleep, 1000 
    }
    Label2: 
    Loop,       
    {
        PixelGetColor, color2, 780, 430, Alt              ; check for game ready button
        if (color2 = 0x1F1B1A)                            ; if game ready button found
        {
            Click 780, 430                                ; click accept game button
            break
        }
        Sleep, 1000
    }
    Loop,       
    {
        PixelGetColor, color3, 1600, 900, Alt             ; check for loaded into game
        PixelGetColor, color4, 502, 390, Alt              ; check for returned to finding game
		if (color3 = 0x422410)                            ; if loaded into game
        {
            break                                         ; go to next step
        }
        else if (color4 = 0xBBBBBB)                       ; otherwise if returned to finding game
		{ 
		    Goto, Label2                                 ; go back to checking for game ready button (label2)
		}
        Sleep, 1000
    }
	 Loop,       
    {
        PixelGetColor, color5, 200, 102, Alt              ; check for being on team 1
        PixelGetColor, color6, 1275, 102, Alt             ; check for being on team 2 
		if (color5 = 0x00FB00)                            ; if on team 1
        {
		    Click 382, 775                                ; select character
		    Sleep, 1000                                   ; wait 1 second
			Click 1100, 775								  ; start game
            break                                         ; go to next step   
        }
		else if (color6 = 0x0000FB)                       ; otherwise if on team 2
		{ 
		    Click 382, 775                                ; select character
		    Sleep, 1000                                   ; wait 1 second
			Click 1100, 775								  ; start game
			Goto, Label3                                 ; go to team 2 step (label3)
		}
        Sleep, 1000 
    }
	 Loop,       
    {                                                     ; team 1
        PixelGetColor, color7, 1390, 680, Alt			  ; check for game over	      
        if (color7 != 0x232121)                           ; if game over not found  
        {
            Click right 275, 825						  ; right click a location
        }
		else if (color7 = 0x232121)                       ; otherwise if game over found
		{ 
		   Click 1390, 680                                ; click exit game button
		   Goto, Label1                                  ; go to start of script (label1)                                                                  
		}
        Sleep, 1000 
    }
	 Label3:
	 Loop,       
    {                                                     ; team 2
        PixelGetColor, color7, 1390, 680, Alt             ; check for game over
        if (color != 0x232121)   					      ; if game over not found
        {
            Click right 25, 1060                          ; right click a location
        }
		else if (color6 = 0x232121)                       ; otherwise if game over found
		{ 
		    Click 1390, 680                               ; click exit game button
		    Goto, Label1                                 ; go to start of script
		}
        Sleep, 1000 
    }
return
User avatar
boiler
Posts: 2653
Joined: 21 Dec 2014, 02:44

Re: need help to change script

11 Feb 2015, 00:59

I'm not saying I know it will work properly. I haven't really studied it to know what it's trying to do. But based on what you described, I think Goto is what you were trying to achieve where you had Gosub statements.

Regarding stopping the script, since you would be pressing one hotkey to stop the execution of a thread spawned by another hotkey, I'm not sure what the cleanest way to do it is, but F2::Reload would work.
Guest

Re: need help to change script

11 Feb 2015, 01:05

i see well i also can't use goto in the same way because it's the same error. if you are able to explain more about subroutines that would help because when someone suggested to use gosub/goto i just added it how i thought i could but it was wrong. i am noob and don't know what i'm doing much.
enthused
Posts: 94
Joined: 27 Dec 2014, 03:28

Re: need help to change script

11 Feb 2015, 01:24

I'm not sure I understand what you are trying to do.
You want label1 to start and check color1?
Do you want after that label2 and label3 to always happen?

can you walk me through your program?

Thanks as I'm learning too and a lot of times I need help understanding what is happening in the code.
User avatar
boiler
Posts: 2653
Joined: 21 Dec 2014, 02:44

Re: need help to change script  Topic is solved

11 Feb 2015, 01:44

Well, if you use subroutines, you can't just jump around to different points in the big block of code you have under the F1 hotkey. You would break them each out separately, something like this:

Code: Select all

color1 =
color2 =
color3 =
color4 =
color5 = 
color6 =
color7 =

return ; <<<<< This marks the end of the auto-execute section.  You should put this here, then list other code (subroutines, functions, and hotkey definitions) after it.


F1::    
PixelGetColor, color1, 410, 561, Alt                      ; press f1 to check to start or not
if (color1 = 0x0000CB)                                    ; if should start go to next step
{                                    ; <<<<< Need to include everything you want to occur if the if statement is true
                                     ;       in braces {} unless it's a single line of code
	Gosub Label1
	Gosub Label2
	; it looks like your intent was for Label2's code to execute immediately after Label1's code,
	; so that's why they're both listed within this block of code.  and i didn't include Label3
	; because it looked like that gets called from within the label2 block of code
}
return

Label1:
	Loop,       
	{
		PixelGetColor, color1, 410, 561, Alt              ; press f1 to check to start or not
		if (color1 = 0x0000CB)                            ; if should start
		{
			Click 670, 300                                ; click find game 
			break
		}
		Sleep, 1000 
	}
return ; <<<<< This marks the end of the subroutine

Label2: 
	; in general, use flow of control statements like loops with while or until, or break from loops, not goto
	Loop
	{
		; your code here
	} until color4 != 0xBBBBBB                            ; don't continue until color 4 is no longer 0xBBBBBB
	Sleep, 1000
	; more code here
return

Label3:
	; your code for label 3
return
This is very rough because I don't know what your code is doing, but you would generally layout subroutines like that, not all within the same block of code. One subroutine can call another, but then it will return back to the subroutine that called it when it is complete. You need to figure out the logic on how you want it to flow. It might be different for you to think about at first, but it supports a much more logical flow of code then a bunch of goto's that leave you with what's known as spaghetti code because you can't really trace what's happening easily.
Guest

Re: need help to change script

11 Feb 2015, 02:28

i'll go over what you wrote to see if i understand. i update my code which still gives the error but at least im not using goto to break loop. maybe you will understand better what i wanted with this version. basically every step checks every second for a color and does something when it finds it. once a color is found it moves to the next step. then the final step sends it to loop 1 again which is a loop thats checks if it should begin the process again. the reason loop 1 is the same as the f1 buttun command is because f1 just starts the script and when the sript if the script is on the second round for all the steps it will need that first loop to check it it shound run (so i dont have to let it finish then press f1 again).

Code: Select all

color1 =
color2 =
color3 =
color4 =
color5 = 
color6 =
color7 =
failedtoload = 
team2 =
gameover =


F1::    
PixelGetColor, color1, 410, 561, Alt                      ; press f1 to check to start or not
if (color1 = 0x0000CB)                                    ; if should start go to next step
    Loop1:
    Loop,       
    {
        PixelGetColor, color1, 410, 561, Alt              ; check to start or not
        if (color1 = 0x0000CB)                            ; if should start
        {
            Click 670, 300                                ; click find game 
            break                                         ; continue
        }
        Sleep, 1000 
    }
    Loop2: 
    Loop,       
    {
        PixelGetColor, color2, 780, 430, Alt              ; check for game ready button
        if (color2 = 0x1F1B1A)                            ; if game ready button found
        {
            Click 780, 430                                ; click accept game button
            break                                         ; continue
        }
        Sleep, 1000
    }
    Loop3:
	Loop,       
    {
        PixelGetColor, color3, 1600, 900, Alt             ; check for loaded into game
        PixelGetColor, color4, 502, 390, Alt              ; check for returned to finding game
		if (color3 = 0x422410)                            ; if loaded into game
        {
            failedtoload = 0
			break                                         ; continue 
        }
        else if (color4 = 0xBBBBBB)                       ; otherwise if returned to finding game
		{ 
		    failedtoload = 1                               
		    break                                         ; continue
		}
        Sleep, 1000
    }
	if (failedtoload = 1)
	{
		Goto, Loop2                                       ; return to checking for game ready button (Loop2)
	}
	Loop4:
	Loop,       
    {
        PixelGetColor, color5, 200, 102, Alt              ; check for being on team 1
        PixelGetColor, color6, 1275, 102, Alt             ; check for being on team 2 
		if (color5 = 0x00FB00)                            ; if on team 1
        {
		    Click 382, 775                                ; select character
		    Sleep, 1000                                   ; wait 1 second
			Click 1100, 775								  ; start game
            team2 = 0
			break                                         ; continue   
        }
		else if (color6 = 0x0000FB)                       ; otherwise if on team 2
		{ 
		    Click 382, 775                                ; select character
		    Sleep, 1000                                   ; wait 1 second
			Click 1100, 775								  ; start game
			team2 = 1
			break                                         ; continue
		}
        Sleep, 1000 
    }
	if (team2 = 1)
	{
		Goto, Loop6                                       ; continue to team 2 commands(Loop2)
	}
	Loop5:
	Loop,       
    {                                                     ; team 1
        PixelGetColor, color7, 1390, 680, Alt			  ; check for game over	      
        if (color7 != 0x232121)                           ; if game over not found  
        {
            Click right 275, 825						  ; right click a location
        }
		else if (color7 = 0x232121)                       ; otherwise if game over found
		{ 
		   Click 1390, 680                                ; click exit game button
		   gameover = 1								                                                                    
           break		                                  ; continue
		}
        Sleep, 1000 
    }
	if (gameover = 1)
	{	
		Goto, Loop1									      ; return to check to start or not (Loop1)
	}
	Loop6:
	Loop,       
    {                                                     ; team 2
        PixelGetColor, color7, 1390, 680, Alt             ; check for game over
        if (color != 0x232121)   					      ; if game over not found
        {
            Click right 25, 1060                          ; right click a location
        }
		else if (color6 = 0x232121)                       ; otherwise if game over found
		{ 
		    Click 1390, 680                               ; click exit game button
		    break                                         ; continue
		}
        Sleep, 1000 
    }
	Goto, Loop1
	return
Guest

Re: need help to change script

11 Feb 2015, 02:37

also theres at least a couple mistakes in the green writing in this version so just ignore any green writing the says something wrong.
Guest

Re: need help to change script

11 Feb 2015, 02:52

in your examples of subroutines i understand how that works now but it also seems the same as just having one loop written on top of the other. so in your i think loop 1 and 2 would work fine but then if i added loop 3 to that list as a label then how would the script know to go to loop 2 or loop 4? loop 3 is the one which deals with that but i had that info inside the loop which made an error.
Guest

Re: need help to change script

11 Feb 2015, 09:27

ok i tried to rewrite it as it was suggested. i'm not sure if i did it right but theres not any errors. it also doesn't seem to work completely right (not clicking some places it should) but that could be a number mistake or something i need to check over again. if anyone can tell if the code structure is good that would be good to know.

Code: Select all

color1 =
color2 =
color3 =
color4 =
color5 = 
color6 =
color7 =
failedtoload = 
team2 =
return

F1::    
PixelGetColor, color1, 410, 561, Alt                      ; press f1 to check to start or not
if (color1 = 0x0000CB)                                    ; if should start
	{
		Gosub, Loop1									  ; start loop1
		Gosub, Loop2									  ; start loop2
		Gosub, Loop3                                      ; start loop3
		if (failedtoload = 0)                             ; if loaded into game
		{
			Gosub, Loop4                                  ; start loop4
		}
	    else if (failedtoload = 1)                        ; otherwise if failed to load
		{
			Gosub, Loop2								  ; start loop2
		}
	    if (team2 = 0)									  ; if on team 1
	    {
			Gosub, Loop5                                  ; start loop5
		}
	    else if (team2 = 1)								  ; otherwise if on team 2
	    {
			Gosub, Loop6								  ; start loop6
		}
		Gosub, Loop1									  ; start loop1
	}    
return
	
	Loop1:
    Loop,       
    {
        PixelGetColor, color1, 410, 561, Alt              ; check to start or not
        if (color1 = 0x0000CB)                            ; if should start
        {
            Click 670, 300                                ; click find game 
            break                                         ; end loop
        }
        Sleep, 1000 
    }
    return
	
	Loop2: 
    Loop,       
    {
        PixelGetColor, color2, 780, 430, Alt              ; check for game ready button
        if (color2 = 0x1F1B1A)                            ; if game ready button found
        {
            Click 780, 430                                ; click accept game button
            break                                         ; end loop
        }
        Sleep, 1000
    }
    return
	
	Loop3:
	Loop,       
    {
        PixelGetColor, color3, 1600, 900, Alt             ; check for loaded into game
        PixelGetColor, color4, 502, 390, Alt              ; check for failed to load
		if (color3 = 0x422410)                            ; if loaded into game
        {
            failedtoload = 0
			break                                         ; end loop 
        }
        else if (color4 = 0xBBBBBB)                       ; otherwise if failed to load
		{ 
		    failedtoload = 1                               
		    break                                         ; end loop
		}
        Sleep, 1000
    }
	return
	
	Loop4:
	Loop,       
    {
        PixelGetColor, color5, 200, 102, Alt              ; check for being on team 1
        PixelGetColor, color6, 200, 102, Alt              ; check for being on team 2 
		if (color5 = 0x00FB00)                            ; if on team 1
        {
		    Click 382, 775                                ; click select character
		    Sleep, 1000                                   ; wait 1 second
			Click 1100, 775								  ; click start game
            team2 = 0
			break                                         ; end loop   
        }
		else if (color6 = 0x0000FB)                       ; otherwise if on team 2
		{ 
		    Click 382, 775                                ; click select character
		    Sleep, 1000                                   ; wait 1 second
			Click 1100, 775								  ; click start game
			team2 = 1
			break                                         ; end loop
		}
        Sleep, 1000 
    }
	return
	
	Loop5:                                                ; team 1
	Loop,                                                 
    {                                                     
        PixelGetColor, color7, 1390, 680, Alt			  ; check for game over	      
        if (color7 != 0x232121)                           ; if game over not found  
        {
            Click right 275, 825						  ; right click a location
        }
		else if (color7 = 0x232121)                       ; otherwise if game over found
		{ 
		   Click 1390, 680                                ; click exit game button
		   break		                                  ; end loop
		}
        Sleep, 1000 
    }
	return
	
	Loop6:                                                ; team 2
	Loop,                                                
    {                                                     
        PixelGetColor, color7, 1390, 680, Alt             ; check for game over
        if (color7 != 0x232121)   					      ; if game over not found
        {
            Click right 25, 1060                          ; right click a location
        }
		else if (color7 = 0x232121)                       ; otherwise if game over found
		{ 
		    Click 1390, 680                               ; click exit game button
		    break                                         ; end loop
		}
        Sleep, 1000 
    }
	return


	
User avatar
boiler
Posts: 2653
Joined: 21 Dec 2014, 02:44

Re: need help to change script

11 Feb 2015, 09:44

Looks like you need a loop around all the code in your main F1 routine. Otherwise, you would have to press F1 to start it again after it made it through the loop. That's not how I understood what you want.

Also, the Gosub, Loop1 at the bottom of that routine doesn't make sense. At that point, it will do the part that finds a game, then just stop. Putting that Gosub there doesn't take you back to the top where it runs through all of the routines again. If you want that, that's why you need a loop around all of that.
Guest

Re: need help to change script

11 Feb 2015, 11:01

how is this? i think this fixes the problem and does what i want.

Code: Select all

color1 =
color2 =
color3 =
color4 =
color5 = 
color6 =
color7 =
failedtoload = 
team2 =
return


F1::    
Loop,
{
PixelGetColor, color1, 410, 561, Alt
if (color1 = 0x0000CB)
	{
			Gosub, Label1								  ; start label1
			Gosub, Label2								  ; start label2
			Gosub, Label3                         	      ; start label3
		if (failedtoload = 0)                  		      ; if loaded into game
		{
			Gosub, Label4                         		  ; start label4
		}
		else if (failedtoload = 1)              		  ; otherwise if failed to load
		{
			Gosub, Label2						 		  ; start label2
		}
		if (team2 = 0)									  ; if on team 1
		{
			Gosub, Label5                        		  ; start label5
		}
		else if (team2 = 1)						 		  ; otherwise if on team 2
		{
			Gosub, Label6						 		  ; start label6
		}                                              
    }
else if (color1 != 0x0000CB)
	break
}                                                      
return                                                   


Label1:                                                          
{                                                          
Click 670, 300                                		  ; click find game 
}                                             
return
	
	
Label2: 
Loop,       
{
    PixelGetColor, color2, 780, 430, Alt              ; check for game ready button
    if (color2 = 0x1F1B1A)                            ; if game ready button found
    {
        Click 780, 430                                ; click accept game button
        break                                         ; end loop
    }
    Sleep, 1000
}
return
	
	
Label3:
Loop,       
{
    PixelGetColor, color3, 1600, 900, Alt             ; check for loaded into game
    PixelGetColor, color4, 502, 390, Alt              ; check for failed to load
    if (color3 = 0x422410)                            ; if loaded into game
    {
        failedtoload := 0
	  	break                                         ; end loop 
    }
    else if (color4 = 0xBBBBBB)                       ; otherwise if failed to load
    { 
	    failedtoload := 1                               
		break                                         ; end loop
	}
    Sleep, 1000
}
return
	
	
Label4:
Loop,       
{
    PixelGetColor, color5, 200, 102, Alt              ; check for being on team 1
    PixelGetColor, color6, 200, 102, Alt              ; check for being on team 2 
	if (color5 = 0x00FB00)                            ; if on team 1
    {
	    Click 382, 775                                ; click select character
		Sleep, 1000                                   ; wait 1 second
		Click 1100, 775								  ; click start game
        team2 := 0
		break                                         ; end loop   
    }
	else if (color6 = 0x0000FB)                       ; otherwise if on team 2
	{ 
		Click 382, 775                                ; click select character
		Sleep, 1000                                   ; wait 1 second
	    Click 1100, 775								  ; click start game
		team2 := 1
		break                                         ; end loop
	}
    Sleep, 1000 
}
return
	
	
Label5:                                                ; team 1
Loop,                                                 
{                                                     
    PixelGetColor, color7, 1390, 680, Alt			  ; check for game over	      
    if (color7 != 0x232121)                           ; if game over not found  
    {
        Click right 275, 825						  ; right click a location
    }
	else if (color7 = 0x232121)                       ; otherwise if game over found
	{ 
		Click 1390, 680                                ; click exit game button
		break		                                  ; end loop
	}
    Sleep, 1000 
}
return
	
	
Label6:                                                ; team 2
Loop,                                                
{                                                     
    PixelGetColor, color7, 1390, 680, Alt             ; check for game over
    if (color7 != 0x232121)   					      ; if game over not found
    {
        Click right 25, 1060                          ; right click a location
    }
	else if (color7 = 0x232121)                       ; otherwise if game over found
	{ 
		Click 1390, 680                               ; click exit game button
		break                                         ; end loop
	}
    Sleep, 1000 
}
return
User avatar
boiler
Posts: 2653
Joined: 21 Dec 2014, 02:44

Re: need help to change script

11 Feb 2015, 12:51

It's looking pretty good. Just noticed something you're doing with if and else/if that isn't necessarily wrong, but is unnecessary and less efficient, so it's good to get into the correct practice.

In the F1:: section, you don't need the if (color1 != 0x0000CB) after the else statement. The only way it gets there is if that condition is true because you have the opposite expression in the original if statement. It would still work your way, but it's redundant. So that line should just be else. But rather than else and break, you could also put until (color1 != 0x0000CB) after the last } instead.

Same as above with if (failedtoload = 0) and else if (failedtoload = 1). No reason for the second if. Just use else. And again with team2 and later with color7.

By the way, this is more style than anything, but it can really help the readability of your code, especially in a case like this where you have a bunch of these in a row. If you have a single command after an if or an else, like where you have

Code: Select all

if (failedtoload = 0)
{
     Gosub, Label4
}
...you don't need the braces. Where there is one command after it, you can make it:

Code: Select all

if (failedtoload = 0)
     Gosub, Label4
...which especially in this case, would really tighten up that section and make it a lot easier to see what's going on.

Then here's something I happened to notice that might not be a typo, but I thought I'd mention it. In Label 4, did you mean to check if color5 is 0x00FB00 and if not, check if color6 is 0x0000FB. It just seems like a coincidence that one color is 0x00FB00 and the other is 0x0000FB, so I thought it might be a typo.
User avatar
boiler
Posts: 2653
Joined: 21 Dec 2014, 02:44

Re: need help to change script

11 Feb 2015, 13:10

Also, to implement your F2 key to stop checking, now that you have it broken out into subroutines, it's possible to implement this cleanly without needing to use Reload.

Change the beginning of F1:: from:

Code: Select all

F1::    
Loop,
{
PixelGetColor, color1, 410, 561, Alt
to:

Code: Select all

F1::    
colorcheck := 1
Loop,
{
if not colorcheck ; meaning if colorcheck = 0
     return ; stop executing this hotkey thread
PixelGetColor, color1, 410, 561, Alt
and add a new hotkey definition:

Code: Select all

F2::colorcheck := 0
And if you wanted that F2 to stop checking even if it got past the first part (like you're already into the downstream checks because the game has started), you would have to add

Code: Select all

if not colorcheck
     return
into the body of each of the loops of the various subroutines.

If all that sounds like too much trouble, then forget all that and simply add F2::Reload
Guest

Re: need help to change script

11 Feb 2015, 21:35

i realize i made a mistake. failedtoload = 0 doing Label4 is what i want but if failedtoload = 1 i want label 3 (the one with this loading info) to loop with Label 2 so until the failedtoload becomes 0. but now i don't know how to do this again because it seems like my problem is always needing gosub inside loops. how can i make Label 3 a test Label 2 has to pass to get to Label 4? i think the rest is ok...
User avatar
boiler
Posts: 2653
Joined: 21 Dec 2014, 02:44

Re: need help to change script

11 Feb 2015, 22:51

There's nothing that says you can't Gosub form inside loops. You can't use Gosub to break out of the loop because it will eventually return back to inside the loop. So you just need the loop to handle it correctly when you return from it.

It sounds like what you want is this:

Code: Select all

Gosub, Label1
Gosub, Label2
Gosub, Label3
if (failedtoload = 0)
    Gosub, Label4
else
{
    While (failedtoload = 1)
    {
        Gosub, Loop2
        Gosub, Loop3
    }
}
Gosub, Label4
User avatar
boiler
Posts: 2653
Joined: 21 Dec 2014, 02:44

Re: need help to change script

11 Feb 2015, 22:56

Actually, this is even better:

Code: Select all

Gosub, Label1
Loop
{
    Gosub, Loop2
    Gosub, Loop3
} until failedtoload = 0
Gosub, Label4

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot] and 88 guests