Loop not looping (trying to click when color != something)

Get help with using AutoHotkey and its commands and hotkeys
SmolTurtle

Loop not looping (trying to click when color != something)

21 Jul 2018, 15:08

Hi everyone, i'm trying to click and hold somewhere and then click elsewhere when a color changes but do nothing when the color stays the same and i want it to keep trying ever X seconds until i stop it with a hotkey or anything, here's my code:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance Force

^q::
Loop
{
PixelGetColor, Color, 1100, 750
If Color != 0x545160
{
    Click down, 850,350
    Sleep 50
    Click up
    Click down, 1290, 447        
    Sleep, 2500         
    Click up            
    Sleep, 250
    Click down, 850,350
    Sleep 50
    Click up
}
return
F2::Break
}
Send ^q
This code does its job well but only once and doesn't loop at all
SmolTurtle

Re: Loop not looping (trying to click when color != something)

21 Jul 2018, 15:31

Update on this:

I deleted the "return" which was obviously getting me out of my loop and now it loops well until the color goes back to 0x545160, when it does so, it stops looping, so basically it still works only once when it manages to do its job here's my new code:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance Force

^q::
Loop
{
PixelGetColor, Color, 1100, 750
If Color != 0x545160
{
    Click down, 850,350
    Sleep 50
    Click up
    Click down, 1290, 447        
    Sleep, 2500         
    Click up            
    Sleep, 250
    Click down, 850,350
    Sleep 50
    Click up
    
}
Send ^q
F2::Break
}
User avatar
gregster
Posts: 1482
Joined: 30 Sep 2013, 06:48

Re: Loop not looping (trying to click when color != something)

21 Jul 2018, 16:12

This code has some flaws. Send ^q is unreachable. F2::Break doesn't do what you intend - well, the return inside the loop ends it anyway after the first iteration.

I assume, this will be closer to your goal:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance Force

^q::
toggle := true
While toggle
{
	PixelGetColor, Color, 1100, 750
	If Color != 0x545160
	{
	    Click down, 850,350
	    Sleep 50
	    Click up
	    Click down, 1290, 447        
	    Sleep, 2500         
	    Click up            
	    Sleep, 250
	    Click down, 850,350
	    Sleep 50
	    Click up
	}
}
return

F2::toggle := !toggle
Esc::ExitApp 	; hit Escape to end the script
Edited
SmolTurtle

Re: Loop not looping (trying to click when color != something)

21 Jul 2018, 16:24

Thanks a ton, works exactly as I wanted, i figured out by myself that the return was badly placed but didn't think of using a while

Return to “Ask For Help”

Who is online

Users browsing this forum: 8bitgunny, blad4, Ggirf14, Google [Bot], Hampoon, hidefguy, L3628QH, labrint, rogerrabbitthefirst, swagfag and 56 guests