我只想让脚本在一个成功的PixelSearch之后才能继续。即。
这就是我现在所拥有的。我该用什么代替休息?
;stuff
PixelSearch, Px, Py, 995, 256, 999, 262, 0x84BCD1, 40, Fast
if ErrorLevel = 0
break //???
;stuff
PixelSearch, Px, Py, 995, 256, 999, 262, 0x84BCD1, 40, Fast
if ErrorLevel = 0
break //???
;stuff
PixelSearch, Px, Py, 995, 256, 999, 262, 0x84BCD1, 40, Fast
if ErrorLevel = 0
break
}
发布于 2020-12-10 15:05:08
简短回答:您可能希望用return
代替break
。
长答案:当您试图退出任何类型的可循环语句时,都会使用Break
和Continue
。为了停止执行脚本的大多数其他部分,例如自动执行部分、热键、子程序或函数,您可以使用返回语句。此外,我不认为您的脚本的其他部分正在按您的意愿工作。例如,根据当前ErrorLevel
的用法,只有在屏幕上找不到上述像素时,脚本才会有效地继续运行。这是因为检查程序是否应该停止执行的条件语句正在检查是否为ErrorLevel = 0
。从先前链接的文档中,只有在成功找到像素的情况下,ErrorLevel才会是0,这意味着将返回一个非零值,即没有找到该像素。为了在代码中解决这个问题,只要if ErrorLevel = 0
出现在代码中,我们就可以简单地将它更改为if ErrorLevel
。
修改代码
;Move other stuff up here
PixelSearch, Px, Py, 995, 256, 999, 262, 0x84BCD1, 40, Fast
if ErrorLevel
return
;stuff
PixelSearch, Px, Py, 995, 256, 999, 262, 0x84BCD1, 40, Fast
if ErrorLevel
return
;stuff
PixelSearch, Px, Py, 995, 256, 999, 262, 0x84BCD1, 40, Fast
if ErrorLevel
return
MsgBox, complete
;put code that you want to run after the condition is met here
return
发布于 2020-12-08 17:29:49
注:这是在澄清之前对问题的一个版本的答复。我发布了一个新的答案,应该能更好地解决这个问题。
根据我的理解,下面是一个GoSub解决方案,如果PixelSearch无法找到像素/ ErrorLevel =0,则运行一个子例程:
PixelSearch, Px, Py, 995, 256, 999, 262, 0x84BCD1, 40, Fast
if ErrorLevel = 0
gosub, subroutine
PixelSearch, Px, Py, 995, 256, 999, 262, 0x84BCD1, 40, Fast
if ErrorLevel = 0
gosub, subroutine
subroutine:
;insert whatever code you want to run in between the line above and the return
MsgBox, This is a subroutine. No matching pixels were found
return
https://stackoverflow.com/questions/65203153
复制相似问题