该脚本将两个参数值传递给脚本的另一个实例。所以内置参数变量 0 包含传递参数的数量。1 在下面的示例“C:/Windows”中,2 是“/switchtest”
可以使用函数外部的传统方法(使用单个等号)将参数值分配给 strParam1 和 strParam2。但是,在函数内部,分配失败。
如果将它们分配在带有 := 符号的循环中,它似乎可以工作。
为什么?任何人都可以解释这种行为吗?
strParam1 = %1%
strParam2 = %2%
msgbox, 64, Outside the Function, number of parameters:%0%`npath: %strParam1%`nswitch: %strParam2%
test_params()
strPath := "C:/Windows"
strSwitch := "/switchtest"
RunWait "%A_AhkPath%" "%A_ScriptFullPath%" "%strPath%" "%strSwitch%"
test_params() {
global 0
; this works
; loop %0%
; strParam%A_Index% := %A_Index%
; this causes an error: "This dynamic variable is blank. If this variable was not intended to be dynamic, remove the % symbols from it."
; strParam1 := %1%
; strParam2 := %2%
; this passes empty values; however, this method works outside the function.
strParam1 = %1%
strParam2 = %2%
msgbox, 64, Inside the Function, number of parameters:%0%`npath: %strParam1%`nswitch: %strParam2%
if strParam2
exitapp
}