Sometimes, we need to pass a VarRef to a function with ByRef parameters, but don't want the variable to be changed. For example:
[Code1:]
Code: Select all
f(&x1,&x2,&x3,&x4,&x5){
x1:=x2:=x3:=x4:=x5:=x1*x2+x3+x4+x5
}
a:=b:=c:=d:=e:=1
f(&a,&$b,&c,&d,&$e)
f(&$e,&c,&$b,&$a,&d)
f(&a,&b,&c,&$d,&e)
; .......................
[Code2:]
Code: Select all
f(&x1,&x2,&x3,&x4,&x5){
x1:=x2:=x3:=x4:=x5:=x1*x2+x3+x4+x5
}
a:=b:=c:=d:=e:=1
b1:=b,e1:=e
f(&a,&b1,&c,&d,&e1)
e2:=e,b2:=b,a2:=a
f(&e2,&c,&b2,&a2,&d)
d3:=d
f(&a,&b,&c,&d3,&e)
; .......................
But this feature can solve it. Every time we use &$, script will assign the right hand to a temporary variable without naming. The refs of $Var1 are different each time $Var1 is occurred. So we call them anonymous variable or temporary variable.
Also sometimes, we need simply pass values such as string or integer, to ByRef parameters just to make it run.
In this code below, $7... represents an anonymous and temporary variable.
[Code3:]
Code: Select all
f(&x1,&x2,&x3,&x4,&x5){
return x1:=x2:=x3:=x4:=x5:=x1*x2+x3+x4+x5
}
f(&$7,&$5,&$7,&$8,&$3) ; It will return 7*5+7+8+3=53
[Code4:]
Code: Select all
val:=0
f2(x,y)=>outputdebug(x)
f2(Var, $Var++)
;Var will not be influenced by Var++ this time and pass 0.