0

I am relatively new in AHK so I apologize for my basic lack of knowledge. I have the following script:

xpos1=
xpos2=
SetMouseDelay,-1
SetBatchLines, -1
col_outher_circle=0xFFFFFF
col_gray_area=0x46362E
col_inner_circle=0x5C80BC
col_background=0x352923
Process, Priority,, High

findTarget(xpos1, ypos1, xpos2, ypos2){
    PixelSearch, Px, Py, xpos1, ypos1, xpos2, ypos2, col_inner_circle, 5, Fast
    Send {Space}
}
    
f1::
If xpos1 =  
    {
    MouseGetPos, xpos1, ypos1 
    Msgbox, xpos1=%xpos1% and ypos1=%ypos1% are set!
    Return
    }
If xpos2 =  
    {
    MouseGetPos, xpos2, ypos2
    Msgbox, xpos2=%xpos2% and ypos2=%ypos2% are set!
    }
    
Loop{
    PixelSearch, grayXleft, grayY, xpos1, ypos1, xpos2, ypos2, col_gray_area, 5, Fast
    Msgbox, grayXleft=%grayXleft% / grayY=%grayY% 
    grayXright:=getRightXofGray(grayXleft, grayY) ; return result here is nothing and     grayXright is set to blank
    Msgbox, no more gray. grayXleft=%grayXleft% and grayXright=%grayXright%
    findTarget(xpos1, ypos1, xpos2, ypos2)
}

getRightXofGray(grayXleft, grayY){
    PixelGetColor, Color, grayXleft, grayY
    grayXleft:=grayXleft+15
    PixelGetColor, NewColor, grayXleft, grayY
    Msgbox, Color is %Color% and NewColor is %NewColor%
    if (Color == NewColor) {
        Msgbox, newcolor is gray and grayXleft=%grayXleft% / grayY=%grayY% 
        getRightXofGray(grayXleft, grayY)
    } else {
        Msgbox, newcolor is NNNNNNNOOOOOOTTTTTTTTTTTTTTTTTTTTTTT gray
        return grayXleft-15
    }
}

f3::Pause
f2::
Msgbox, Reloading script..
reload  ;exitapp

I tried using Global for grayXright as well but it is still blank. When I output the info inside the else case in the getRightXofGray() function all is good.

Where am I making a mistake?

4
  • You're running recursion without a return. Commented Apr 14 at 10:11
  • I have a return. Each loop increases Y axis that's being search by 15 and checks if the previously taken pixel color is the same as the new one. If different - prints msg and returns. The msgbox appears but the return does not take effect Commented Apr 15 at 11:30
  • if (Color == NewColor) branch is missing a return. Commented Apr 15 at 15:11
  • of course. If add a return, there will be no recursion :D. I fixed my situation without using this code, still very curious why it does not set the return value though.. It goes in this block and prints the msg } else { Msgbox, newcolor is NNNNNNNOOOOOOTTTTTTTTTTTTTTTTTTTTTTT gray return grayXleft-15 } Commented Apr 16 at 11:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.