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
}