I tried to show you the loop method because it will be difficult to make a script that will run well by trying to jump back and forth between subroutines using
GoSub. In the loop I made of your script whenever a return is encountered it returns to the beginning of the loop, hence in effect back to the "MONSTER" subroutine.
It's a little more burdensome since the code can become a little more difficult to read but ultimately it should what you want it to do better than the method you're currently attempting. You can comment in the script in much the same way that you did before to keep track of things, like this:
Code:
Loop, 90
{
/*
Checks to see if the monster is dead
*/
ImageSearch, MONx, MONy, 0, 0, A_ScreenWidth, A_ScreenHeight, *20 C:\GAME\looted.bmp
if (ErrorLevel) ; if not found proceeds to check for IDS
{
/*
Checks for IDS
*/
ImageSearch, IDSx, IDSy, 0, 0, A_ScreenWidth, A_ScreenHeight, *20 C:\GAME\ids.bmp
if (ErrorLevel) ; if not found proceeds to check for DS
{
/*
Checks for DS
*/
ImageSearch, DSx, DSy, 0, 0, A_ScreenWidth, A_ScreenHeight, *20 C:\GAME\ds.bmp
if (ErrorLevel); if not found proceeds to Attack
{
/*
Checks for Attack
*/
ImageSearch, ATTACKx, ATTACKy, 0, 0, A_ScreenWidth, A_ScreenHeight, *20 C:\GAME\attack.bmp
if (ErrorLevel); if not found proceeds to Heal
{
/*
Checks for Heal
*/
ImageSearch, HEALx, HEALy, 0, 0, A_ScreenWidth, A_ScreenHeight, *20 C:\GAME\heal.bmp
HEALx += 5
HEALy += 5
Click %HEALx% %HEALy%
loop
{
ImageSearch, LOADINGx, LOADINGy, 0, 0, A_ScreenWidth, A_ScreenHeight, *20 C:\GAME\loading.bmp
if (ErrorLevel)
Continue
}
ImageSearch, HUNTx, HUNTy, 0, 0, A_ScreenWidth, A_ScreenHeight, *20 C:\GAME\cg.bmp
HUNTx += 5
HUNTy += 5
Click %HUNTx% %HUNTy%
loop
{
ImageSearch, LOADINGx, LOADINGy, 0, 0, A_ScreenWidth, A_ScreenHeight, *20 C:\GAME\loading.bmp
if (ErrorLevel)
Continue
}
return
}
Else
{
ATTACKx += 5
ATTACKy += 5
Click %ATTACKx% %ATTACKy%
Return
}
}
Else
{
DSx += 5
DSy += 5
Click %DSx% %DSy%
Return
}
}
Else
{
IDSx += 5
IDSy += 5
Click %IDSx% %IDSy%
return
}
}
Else
{
ImageSearch, HEALX, HEALY, 0, 0, A_ScreenWidth, A_ScreenHeight, *20 C:\GAME\heal.bmp
HEALx += 5
HEALy += 5
Click %HEALx% %HEALy%
Loop
{
ImageSearch, LOADINGx, LOADINGy, 0, 0, A_ScreenWidth, A_ScreenHeight, *20 C:\GAME\loading.bmp
if (ErrorLevel)
Continue
}
ImageSearch, HUNTx, HUNTy, 0, 0, A_ScreenWidth, A_ScreenHeight, *20 C:\GAME\cg.bmp
HUNTx += 5
HUNTy += 5
Click %HUNTx% %HUNTy%
Loop
{
ImageSearch, LOADINGx, LOADINGy, 0, 0, A_ScreenWidth, A_ScreenHeight, *20 C:\GAME\loading.bmp
if (ErrorLevel)
Continue
}
Return
}
}
Also, I'd like to point out some shorthand I'm using in the code you might find helpful. You'll notice in places where you're using this:
Code:
if ErrorLevel = 1
<< some action >>
if ErrorLevel = 0
<< some action >>
I use just this:
Code:
if (ErrorLevel)
<< some action >>
The
(ErrorLevel) tells the script to check if ErrorLevel is set to something other than 0, and if it is then it will proceed with some action. Even though you can tell the script to do something if ErrorLevel is 0, in this instance the script will assume by default that if the "if" condition is not met it should break and return to the beginning of the loop (and that's what we want it to do anyway).
Also, in places where you're passing math operations to additional variables:
Code:
ImageSearch, IDSX, IDSY, 0, 0, A_ScreenWidth, A_ScreenHeight, *20 C:\GAME\ids.bmp
if ErrorLevel = 1
{
Gosub DS
}
else
{
2IDSX := IDSX + 5
2IDSY := IDSY + 5
Click %2IDSX% %2IDSY%
I do something slightly different:
Code:
ImageSearch, IDSX, IDSY, 0, 0, A_ScreenWidth, A_ScreenHeight, *20 C:\GAME\ids.bmp
if ErrorLevel = 1
{
Gosub DS
}
else
{
IDSX += 5
IDSY += 5
Click %IDSX% %IDSY%
If you're more comfortable creating a separate variable for those, that's fine, but just know you're not required to. You always add something to a variable and save it to itself:
Code:
ISDX := ISDX + 5
Or you can use the shorthand addition operator to do the exact same thing:
Code:
ISDX += 5
It won't matter that you do so since the ImageSearch command will reset the value of the variables on the next run anyway. You can find more information about those operators on the
Variables and Expressions section of the help manual.