Gosub如何运作?

时间:2013-09-27 17:08:45

标签: autohotkey

请在AutoHotkey中执行以下脚本:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Event  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#Persistent

Gosub, Mylabel
Return

MsgBox, It worked!

MyLabel:
Sleep, 1000
Return

我希望它可以调用MyLabel,即等待1秒,然后弹出消息框。

但事实并非如此。

我在Gosub运作中缺少什么?

1 个答案:

答案 0 :(得分:1)

return电话后面的行gosub

取出它,它会停止剧本。

像这样:

(1) Gosub, Mylabel
; Return

(2) MsgBox, It worked!

(3) MyLabel:
(4) Sleep, 1000
(5) Return

基本上,在Gosub行之后,启动了 Mylabel 背后的代码。 一旦达到return,它就会跳回并继续Gosub之后的行。

这里的执行顺序是(1),跳转到标签(3),运行命令(4),运行return(5)因为先前发出了gosub,所以跳转到(1)之后的行,运行(2)并且你看到了消息。然后代码继续再次传递标签(3),再次运行(4),这次返回(5)完全停止脚本。

相关问题