Counter after finishing a loop

Ask gaming related questions (AHK v1.1 and older)
Seth_Nooby1
Posts: 4
Joined: 14 Mar 2024, 09:23

Counter after finishing a loop

22 Mar 2024, 11:42

So what I'm creating is a macro which will auto grind my game progress (the game is like tower defense where you place unit to defend the base). It basically will run a set of mouse click that are positioned and timing set. When it cleared all the waves or lose, the play again button will appear (which I've used ImageSearch to detect and click the play again button). Everything works just fine and I could just leave it to run for a night.
But what I need help about is that everytime the game lost and won. I want to get a counter for that. Basically a 5 type of counter. 1. Game lost at 2 mins 2. Game lost at 5 mins 3. Game lost at 10 mins 4. Game won/finished at 15 mins.
Where do I put the counter? I read every other forms and can't understand how to use it. I really need example for this.
Also it's like I'm going to the macro over night, wakes up in the morning, press a key and see 5 counters of what I've mentioned.
Here is the code

Code: Select all

F5::Pause
F3::ExitApp
F4::

Start:

Loop
{
; ImgSearch loop until found start button to run a set of mouse clicks
}
; a set of mouse clicks from 0 second to 2 minutes

CoordMode, Pixel, Screen ; 2 minutes game lost checking
ImageSearch, FoundX, FoundY, 0, 0, 1920, 1080, *50 D:\Stuff\playagain1.png
if (ErrorLevel = 0)
{
MouseClick, L, 1284, 782
Goto Start
}
else
; continue a bunch of clicks
CoordMode, Pixel, Screen ; 5 minutes game lost checking
ImageSearch, FoundX, FoundY, 0, 0, 1920, 1080, *50 D:\Stuff\playagain1.png
if (ErrorLevel = 0)
{
MouseClick, L, 1284, 782 ; click "playagain" button
Goto Start ; go back to the start
}
else
; continue a bunch of clicks
CoordMode, Pixel, Screen ; 10 minutes game lost checking
ImageSearch, FoundX, FoundY, 0, 0, 1920, 1080, *50 D:\Stuff\playagain1.png
if (ErrorLevel = 0)
{
MouseClick, L, 1284, 782 ; click "playagain" button
Goto Start ; go back to the start
}
else
; continue a bunch of clicks
CoordMode, Pixel, Screen ; 10 minutes game lost checking
ImageSearch, FoundX, FoundY, 0, 0, 1920, 1080, *50 D:\Stuff\playagain1.png
if (ErrorLevel = 0)
{
MouseClick, L, 1284, 782 ; click "playagain" button
Goto Start ; go back to the start
}
else
; continue a bunch of clicks and finish
CoordMode, Pixel, Screen
Loop ; img search until playagain button is found
{
ImageSearch, FoundX, FoundY, 0, 0, 1920, 1080, *50 D:\Stuff\playagain1.png
}
Until, (ErrorLevel = 0)
MouseClick, L, 1284, 782 ; click "playagain" button
} ;finish the whole thing and go back to the loop beginning
peter_ahk
Posts: 100
Joined: 13 Feb 2024, 14:49

Re: Counter after finishing a loop

22 Mar 2024, 13:12

cant you count things with ++
so if in that loop you add something like
yourvar++ you could keep track
then in the morning you ask for whats in yourvar
Seth_Nooby1
Posts: 4
Joined: 14 Mar 2024, 09:23

Re: Counter after finishing a loop

23 Mar 2024, 02:17

peter_ahk wrote:
22 Mar 2024, 13:12
cant you count things with ++
so if in that loop you add something like
yourvar++ you could keep track
then in the morning you ask for whats in yourvar
I kinda get what you mean but can you show with coding example?
like where exactly do I have to put var++ at and how etc.
Rohwedder
Posts: 7656
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Counter after finishing a loop

26 Mar 2024, 04:16

Hallo,
Error: Unexpected "}"
try:

Code: Select all

	F5::Pause
	F3::ExitApp
	F5::MsgBox,% Info
	F4::
	Counter := 0, Info := "", Done := "Start"
	Start:
	FormatTime, Time,% A_Now, HH:mm:ss 
	Info .= "Counter: " ++Counter " Time: " Time " Done: " Done
	Loop
	{
		; ImgSearch loop until found start button to run a set of mouse clicks
	}
	; a set of mouse clicks from 0 second to 2 minutes
	CoordMode, Pixel, Screen ; 2 minutes game lost checking
	ImageSearch, FoundX, FoundY, 0, 0, 1920, 1080, *50 D:\Stuff\playagain1.png
	if (ErrorLevel = 0)
	{
		MouseClick, L, 1284, 782
		Goto Start
	}
	else
		; continue a bunch of clicks
	CoordMode, Pixel, Screen ; 5 minutes game lost checking
	ImageSearch, FoundX, FoundY, 0, 0, 1920, 1080, *50 D:\Stuff\playagain1.png
	if (ErrorLevel = 0)
	{
		MouseClick, L, 1284, 782 ; click "playagain" button
		Done = 5 minutes game lost checking
		Goto Start ; go back to the start
	}
	else
		; continue a bunch of clicks
	CoordMode, Pixel, Screen ; 10 minutes game lost checking
	ImageSearch, FoundX, FoundY, 0, 0, 1920, 1080, *50 D:\Stuff\playagain1.png
	if (ErrorLevel = 0)
	{
		MouseClick, L, 1284, 782 ; click "playagain" button
		Done = 10 minutes game lost checking
		Goto Start ; go back to the start
	}
	else
		; continue a bunch of clicks
	CoordMode, Pixel, Screen ; 10 minutes game lost checking
	ImageSearch, FoundX, FoundY, 0, 0, 1920, 1080, *50 D:\Stuff\playagain1.png
	if (ErrorLevel = 0)
	{
		MouseClick, L, 1284, 782 ; click "playagain" button
		Done = 10 minutes game lost checking
		Goto Start ; go back to the start
	}
	else
		; continue a bunch of clicks and finish
	CoordMode, Pixel, Screen
	Loop ; img search until playagain button is found
	{
		ImageSearch, FoundX, FoundY, 0, 0, 1920, 1080, *50 D:\Stuff\playagain1.png
	}
	Until, (ErrorLevel = 0)
	MouseClick, L, 1284, 782 ; click "playagain" button
} ;finish the whole thing and go back to the loop beginning <<<  Error:  Unexpected "}"

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 71 guests