A_TickCount Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
VetX
Posts: 5
Joined: 25 Apr 2022, 11:37

A_TickCount

Post by VetX » 24 May 2022, 12:09

Yes im bad at this, wondering how to use A_TickCount in this script, If the pixel is found earlier than lets say 870000, do an action, thats it.

Code: Select all

CoordMode, Pixel, Relative

sleep, 10000
Loop
{
PixelSearch, x, y, 759, 610, 763, 615, 0xE5464F
if (ErrorLevel = 0)
{
Random, rand, 110000, 113000
Sleep, %rand%
Click, Down, 1093 493
Click, Up, 1135 493
sleep, 300
send ^c
sleep, 400
Click, 767, 558
sleep, 400
Send ^v
Sleep 1000
Click, 767, 558
sleep, 300,
Click, 851, 619
sleep, 500 
}
if (ErrorLevel = 0) "in earlier than 870000"
{
fullScriptPath = C:\Users\Vetx\Desktop\CODE.ahk

DetectHiddenWindows, On 
WinClose, %fullScriptPath% ahk_class AutoHotkey
sleep, 500
}

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

Re: A_TickCount  Topic is solved

Post by boiler » 24 May 2022, 12:45

You need to capture the starting value of A_TickCount and compare the current value to that since the actual value is not meaningful unless you really care about how long it has been since the system was started, as opposed to how much time has elapsed since your loop started.

Code: Select all

CoordMode, Pixel, Relative

sleep, 10000
Start := A_TickCount
Loop
{
	PixelSearch, x, y, 759, 610, 763, 615, 0xE5464F
	if (ErrorLevel = 0)
	{
		Random, rand, 110000, 113000
		Sleep, %rand%
		Click, Down, 1093 493
		Click, Up, 1135 493
		sleep, 300
		send ^c
		sleep, 400
		Click, 767, 558
		sleep, 400
		Send ^v
		Sleep 1000
		Click, 767, 558
		sleep, 300,
		Click, 851, 619
		sleep, 500 
	}
	if (ErrorLevel = 0) and ((A_TickCount - Start) < 870000)
	{
		fullScriptPath = C:\Users\Vetx\Desktop\CODE.ahk
		
		DetectHiddenWindows, On 
		WinClose, %fullScriptPath% ahk_class AutoHotkey
		sleep, 500
	}
}

Looks like you were also missing a }, which is easier to see if you indent it like I showed.

Since your first if block has the same condition as one of the conditions of your second one, you could structure it like this without the compound condition for the second one:

Code: Select all

CoordMode, Pixel, Relative

sleep, 10000
Start := A_TickCount
Loop
{
	PixelSearch, x, y, 759, 610, 763, 615, 0xE5464F
	if (ErrorLevel = 0)
	{
		Random, rand, 110000, 113000
		Sleep, %rand%
		Click, Down, 1093 493
		Click, Up, 1135 493
		sleep, 300
		send ^c
		sleep, 400
		Click, 767, 558
		sleep, 400
		Send ^v
		Sleep 1000
		Click, 767, 558
		sleep, 300,
		Click, 851, 619
		sleep, 500 
		if ((A_TickCount - Start) < 870000)
		{
			fullScriptPath = C:\Users\Vetx\Desktop\CODE.ahk
			
			DetectHiddenWindows, On 
			WinClose, %fullScriptPath% ahk_class AutoHotkey
			sleep, 500
		}
	}
}

Post Reply

Return to “Ask for Help (v1)”