0
votes

I have an issue with passing function with parameters in another function as parameter. Code below:

MSG(text) {
MsgBox, %text%
return
}

clicker(X1,Y1,X2,Y2,IMGFILE,ErrorLvlTrue,ErrorLvlFalse) {
CoordMode, Mouse, Window
CoordMode, Pixel, Window
sleep 1000
ImageSearch,OutX1,OutY1,%X1%,%Y1%,%X2%,%Y2%,%IMGFILE%
if (ErrorLevel = 0) {
return ErrorLvlTrue
}
else {
return ErrorLvlFalse
}
}

clicker(0,0,1900,1000,"*20 image_file.bmp",MSG(OutX1),MSG(OutY1))

I just got MSG() function call no matter if it found an image or not.

1

1 Answers

1
votes
Global myCount
clicker(0, 0, 1900, 1000, "*20 image_file.bmp", MSG(OutX1), MSG(OutY1))
Return

MSG(text) 
{
    myCount ++
    MsgBox % ""
    .   "This MSG function is executed earlier " myCount " times" "`n`n" 
    .   "and Your text argument is  -->" text "<--"
}

clicker(X1, Y1, X2, Y2, IMGFILE, ErrorLvlTrue, ErrorLvlFalse) 
{
    If FileExist(IMGFILE)           
        MsgBox % "OK. You have an img file"
    Else
        MsgBox % "Nop. You do not have an img file"
    CoordMode, Mouse, Window
    CoordMode, Pixel, Window
    Sleep, 1000
    ImageSearch, OutX1, OutY1, % X1, % Y1, % X2, % Y2, % IMGFILE
    MsgBox % ""
    .   "Now your clicker function executed" "`n`n"
    .   "X1, Y1  (" X1 ", "Y1 ")`n`n"
    .   "X2, Y2  (" X2 ", "Y2 ")`n`n"
    .   "Image File is  -->" ImgFile "<--`n`n"
    .   "Error Level is  -->" ErrorLevel "<--"    ; "2" means there was a problem
}