Can't toggle script off

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
valin
Posts: 2
Joined: 25 Jul 2021, 23:34

Can't toggle script off

Post by valin » 25 Jul 2021, 23:39

Hi folks, I am probably missing something obvious, but I can't toggle the script off. In my case, I have 2 hotkeys (F1, F2). The F1 one has a loop, and I do the old-fashioned way of toggling and breaking out of the loop, but it is not working properly.

Here is the code, and thanks in advance!

Code: Select all

#MaxThreadsPerHotkey 2
#SingleInstance, Force
#persistent

CoordMode, Mouse, Window
CoordMode, Pixel, Window



setmousedelay -1 
setbatchlines -1

F1::ExecutaScript()
F2::DebugaCor()

DebugaCor(){
	MouseGetPos, MouseX, MouseY
	PixelGetColor, color, %MouseX%, %MouseY%
	MsgBox %color%, %MouseX%, %MouseY%
}

ExecutaScript()
{ 
	Toggle:=!Toggle
  	
	loop
    {
		if (!Toggle) 
			break 

		ClicaAzul()
		ClicaAmarelo()
		ClicaVermelho()
	}
	
	Return
}

ClicaAzul()
{
	ClicaAssist(0xFFFF17)
}

ClicaAmarelo()
{
	ClicaAssist(0x7BFFFF)
}

ClicaVermelho()
{
	ClicaAssist(0x1110FF)
}

ClicaAssist(color)
{
	ClicaAssist1(color)
	ClicaAssist2(color)
}

ClicaAssist1(color)
{
	ClicaPixel(color, 2329, 318, 2455, 431)
}

ClicaAssist2(color)
{
	ClicaPixel(color, 2329, 606, 2455, 713)
}

ClicaPixel(color, x1, y1, x2, y2)
{
	PixelSearch, FoundX, FoundY, x1, y1, x2, y2, color, 0, Fast
	if(ErrorLevel = 0)
	{
		MouseGetPos, StartX, StartY
		MouseClick, left, FoundX, FoundY,, 0
		MouseMove, StartX, StartY
	}
}

Return



aifritz
Posts: 301
Joined: 29 Jul 2018, 11:30
Location: Germany

Re: Can't toggle script off

Post by aifritz » 26 Jul 2021, 00:24

Your var toggle should be static or global

https://www.autohotkey.com/docs/Functions.htm#static
valin
Posts: 2
Joined: 25 Jul 2021, 23:34

Re: Can't toggle script off

Post by valin » 26 Jul 2021, 14:45

aifritz wrote:
26 Jul 2021, 00:24
Your var toggle should be static or global

https://www.autohotkey.com/docs/Functions.htm#static
Awesome, that did the trick. Thanks!
Post Reply

Return to “Ask for Help (v1)”