函数与标签的一般示例
我将演示使用函数与使用标签+ gosub 的基本用法。
在这个例子中,我们将实现简单的功能来添加两个数字并将它们存储在变量中。
功能:
c := Add(3, 2) ; function call
MsgBox, Result: %c%
Add(a, b) { ; This is a function. Put it wherever you want, it doesn't matter.
; the a and b inside of this function are set by the function call above
Return a+b ; the function will return the result of the expression "a+b"
}
带标签(请不要这样做):
a := 3
b := 2
GoSub, Add ; execute the label "Add" then jump back to the next line here
MsgBox, Result: %c%
Return ; without this, the label would be executed again for no reason.
Add: ; This is a label. Please put them at the bottom of your script and use "Return" in a line above.
c := a+b
Return