Infinite FindText Loop Stopping Incorrectly

Ask gaming related questions (AHK v1.1 and older)
saph
Posts: 68
Joined: 25 May 2020, 12:09

Infinite FindText Loop Stopping Incorrectly

30 Jun 2020, 18:46

Hello,

I'm writing a bot for a 2d game I play to get my head around ahk.

I've a function that looks for "Lv.10" or "Lv.11" if it finds either of those two it clicks "attack". If it doesn't it clicks "keep looking". This runs on an infinite loop until "attack" is selected. Once attack is selected, it should then move onto the next function. This works *sometimes* but for some reason the function ends without having found something to attack, i.e. "Lv.10" or "Lv.11".

I've been trying to troubleshoot what's going wrong but I can't seem to figure out why it would stop. I can understand why it might continue forever, i.e. maybe the FindText sections aren't "found" but I can't figure out why it's stopping without having found anything.

I realise the FindText sections use giant search areas, I'm unsure how the fix that yet but I will!

Code: Select all

LIB_Farming_Attack()
{
; assign each findtext graphic
Search1 := "|<Lv.10>*114$21.1y0sDU71w0yCDsllz6CDsllz6CAsllz6CDslk0CDU7lw0w"
Search2 := "|<Lv.11>*137$13.1k0sAT6DX7lXslwMyAT6DX7lXsU"
Search3 := "|<Lv.11>*113$13.1k0s0Q6DX7lXslwMyAT6DX7lXslwE"
Search4 := "|<Lv.10>*114$21.1y0sDU71w0yCDsllz6CDsllz6CDsllz6CDslk0CDU7lw0w"

Loop {
		; perform all findtext searches INSIDE THE LOOP SO THE SEARCHES HAPPEN EACH TIME THROUGH THE LOOP AND ASSIGN NEW VALUES TO RESULT1, 2, 3, 4
		Result1 := FindText(-809-150000, 77-150000, -809+150000, 77+150000, 0, 0, Search1)
		Result2 := FindText(-783-150000, 80-150000, -783+150000, 80+150000, 0, 0, Search2)
		Result3 := FindText(-853-150000, 79-150000, -853+150000, 79+150000, 0, 0, Search3)
		Result4 := FindText(-809-150000, 79-150000, -809+150000, 79+150000, 0, 0, Search4)
		; act on results
		if (Result1 || Result2 || Result3 || Result4) {
			CoordMode, Mouse, Screen
			MouseMove, -500, 1000   ;attack because found Lv.10 or Lv.11
            Sleep 1000
            Click

			} else {
            CoordMode, Mouse, Screen
            MouseMove, -290, 1000   ;keep looking because haven't found Lv.10 or Lv.11
            Sleep 1000
            Click
            Sleep 1000
            }
   
    } Until (Result1 != 0) || (Result2 != 0) || (Result3 != 0) || (Result4 != 0) ; SHOWN AS COMPARED TO 0 BUT CAN ALSO BE (Result1 || Result2 || Result3 || Result4)
return ; USE RETURN AT THE END OF A HOTKEY SUBROUTINE
}
Image
Last edited by saph on 01 Jul 2020, 11:39, edited 1 time in total.
saph
Posts: 68
Joined: 25 May 2020, 12:09

Re: Unsure why loop is stopping

01 Jul 2020, 11:38

Tried using this to highlight if anything obvious was coming up.

Code: Select all

 for i,v (Result1 != 0) || (Result2 != 0) || (Result3 != 0) || (Result4 != 0)
   if (i<=2)
     FindText_MouseTip(ok[i].x, ok[i].y)
Which is a poor attempt at modifying the FindText function:

Code: Select all

; #Include <FindText>

 t1:=A_TickCount, X:=Y:=""

Text:="|<>*13$71.zzztUw000001zzzz1s000003zzzy7k000007zzzwDU00000Dzzzzz000000Tzzzzw000000zzzzzzU00001zzzzzz00C003zzzzzzs0Sk07zzzzzzztwU0DzzzzzzzntU0Tzzzzzzzy000zzzzzzzzw001zzzzzzzzs003zzzzzzzzk007zzzzzzzzk00Dzzzzzzzy000Tzzzzzzzww00zzzzzzzzzsk1zzzzzzzzzk03zzzzzzzzza07zzzzzzzzzzqDzzzzzzzzzzsTzzzzzzzzzzkzzzzzzzzzzzt"

 if (ok:=FindText(-693-150000, 572-150000, -693+150000, 572+150000, 0, 0, Text))
 {
   CoordMode, Mouse
   X:=ok.1.x, Y:=ok.1.y, Comment:=ok.1.id
   ; Click, %X%, %Y%
 }

 MsgBox, 4096, Tip, % "Found :`t" Round(ok.MaxIndex())
   . "`n`nTime  :`t" (A_TickCount-t1) " ms"
   . "`n`nPos   :`t" X ", " Y
   . "`n`nResult:`t" (ok ? "Success !" : "Failed !")

 for i,v in ok
   if (i<=2)
     FindText_MouseTip(ok[i].x, ok[i].y)
While it's not broken anything, it's not doing anything either:

Code: Select all

		if (Result1 || Result2 || Result3 || Result4) {
			CoordMode, Mouse, Screen
			MouseMove, -500, 1000   ;attack because found Lv.10 or Lv.11
            Sleep 1000
            Click

 for i,v in (Result1 != 0) || (Result2 != 0) || (Result3 != 0) || (Result4 != 0)
   if (i<=2)
     FindText_MouseTip(ok[i].x, ok[i].y)

			} else {
            CoordMode, Mouse, Screen
            MouseMove, -290, 1000   ;keep looking because haven't found Lv.10 or Lv.11
            Sleep 1000
            Click
            Sleep 1000
   	        }

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: Shoobis and 104 guests