函式與標籤的一般示例
我將演示使用函式與使用標籤+ 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