Autohotkey 是否可以将pixelsearch和pixelgetcolor结合使用

Autohotkey 是否可以将pixelsearch和pixelgetcolor结合使用,autohotkey,Autohotkey,在这个MMO游戏中,如果我的角色生命值低,它应该传送回城镇并与治疗者NPC对话。它不起作用,我也不知道为什么——当我试图运行我的脚本时,我会出错 CoordMode,像素,相对 坐标模式,鼠标,相对 首页:;按home启动ahk 环 像素搜索,X,Y,0,0,%A_屏幕宽度%,%A_屏幕高度%,0x00ff00,0,快速 在所有非低级编程语言中,您缺少了一个非常重要的编程部分:大括号。(在AutoIt中,我认为您不使用大括号,而是使用基本相同的if和endif/wends等。) 理解AutoH

在这个MMO游戏中,如果我的角色生命值低,它应该传送回城镇并与治疗者NPC对话。它不起作用,我也不知道为什么——当我试图运行我的脚本时,我会出错

CoordMode,像素,相对
坐标模式,鼠标,相对
首页:;按home启动ahk
环

像素搜索,X,Y,0,0,%A_屏幕宽度%,%A_屏幕高度%,0x00ff00,0,快速 在所有非低级编程语言中,您缺少了一个非常重要的编程部分:大括号。(在AutoIt中,我认为您不使用大括号,而是使用基本相同的
if
endif
/
wend
s等。)

理解AutoHotkey中的编译器不关心脚本中的缩进是很重要的

快速示例:

if(healthbar = 0xDEDED6)
send, !3
sleep, 5000
将与

if(healthbar = 0xDEDED6)
{
    send !3
}
sleep, 5000
因此,
sleep,5000
将以任何方式执行,而不管if语句是什么!如果您根本没有使用大括号,任何
if
-语句,
loop
s,
else
parts等将只计算一行。因此,永远不要忽略大括号,只要有一行要执行

如果你想确定,那么尽可能使用大括号

另一件事:如果您以热键触发器(如
home::
)开始任何部分,那么请确保在最后用
return
将其括起来

下面是一个源代码示例。我还更改了一些缩进,但请注意,它们不是必需的,只是为了更好的可读性

CoordMode, Pixel, Relative
CoordMode, Mouse, Relative

Home:: ;press home to start ahk

Loop
{

    PixelSearch, X, Y, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, 0x00ff00, 0, fast ;<<<--this is the monster color to attack
    if(ErrorLevel=0)
    {
        Sleep, 200
        Send, {F4}
        Sleep, 200
        MouseClick, left, 392, 289
        Sleep, 8000
    }
    else
    {
        PixelGetColor, healthbar, 51, 82 ;heres my health bar coordinates
        if (healthbar = 0xDEDED6) ;if my hp bar goes low it will go teleport to town and click to healer npc
        {
           Send !3 ;alt 3 to teleport to town
           Sleep 5000 ;lets wait 5seconds for waiting game loading.
           MouseClick, left, 755, 341 ;click the healer npc
           sleep, 1500
           Send {F5} ;some self skill buffs and stuffs
           sleep, 1500
           Send {F5}
           sleep, 1500
           MouseClick, left, 755, 341   ;click to healer npc again to heal mana
           sleep, 500
           MouseClick, left, 713, 281 ;click to teleporter npc to get back to dungeon to kill monsters
           sleep, 500
           Send {Enter}
           sleep, 1500
           Send {Enter}
        }
        else 
           Send {F8} ;if no monster present in screen, use random teleport skill to search for monsters
    }

}

return  ; ------ end of HOME hotkey


F11::Pause
End::ExitApp ; alt+x to exit ahk
CoordMode,像素,相对
坐标模式,鼠标,相对
主页::;按主页以启动ahk
环
{

PixelSearch,X,Y,0,0,%A_屏幕宽度%,%A_屏幕高度%,0x00ff00,0,fast;您遇到了什么错误?以下是我的错误,如果有,我会很困惑,否则很抱歉,我是新手很好:D如果您需要任何进一步的帮助,请致电
CoordMode, Pixel, Relative
CoordMode, Mouse, Relative

Home:: ;press home to start ahk

Loop
{

    PixelSearch, X, Y, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, 0x00ff00, 0, fast ;<<<--this is the monster color to attack
    if(ErrorLevel=0)
    {
        Sleep, 200
        Send, {F4}
        Sleep, 200
        MouseClick, left, 392, 289
        Sleep, 8000
    }
    else
    {
        PixelGetColor, healthbar, 51, 82 ;heres my health bar coordinates
        if (healthbar = 0xDEDED6) ;if my hp bar goes low it will go teleport to town and click to healer npc
        {
           Send !3 ;alt 3 to teleport to town
           Sleep 5000 ;lets wait 5seconds for waiting game loading.
           MouseClick, left, 755, 341 ;click the healer npc
           sleep, 1500
           Send {F5} ;some self skill buffs and stuffs
           sleep, 1500
           Send {F5}
           sleep, 1500
           MouseClick, left, 755, 341   ;click to healer npc again to heal mana
           sleep, 500
           MouseClick, left, 713, 281 ;click to teleporter npc to get back to dungeon to kill monsters
           sleep, 500
           Send {Enter}
           sleep, 1500
           Send {Enter}
        }
        else 
           Send {F8} ;if no monster present in screen, use random teleport skill to search for monsters
    }

}

return  ; ------ end of HOME hotkey


F11::Pause
End::ExitApp ; alt+x to exit ahk