Code: Select all
P:=1
Q:=2
exchange(P,Q)
MsgBox % "P=" P "`nQ=" Q "`nsuccess"
R:=[1,2]
exchange(R[1],R[2])
MsgBox % "R1=" R[1] "`nR2=" R[2] "`nfail"
exchange(ByRef A,ByRef B)
{
m:=A,A:=B,B:=m
}
Code: Select all
P:=1
Q:=2
exchange(P,Q)
MsgBox % "P=" P "`nQ=" Q "`nsuccess"
R:=[1,2]
exchange(R[1],R[2])
MsgBox % "R1=" R[1] "`nR2=" R[2] "`nfail"
exchange(ByRef A,ByRef B)
{
m:=A,A:=B,B:=m
}
Code: Select all
q:: ;test assigning obj.key to variable
obj := []
obj.1 := "a"
var := obj.1 ;value of obj.1 is stored, not reference to obj.1
obj.1 := "b"
MsgBox, % var ;a ;obj.1's value changed, but var's value didn't change
R := [1, 2]
MsgBox, % "R1=" R.1 "`nR2=" R.2
exchangekeys(R, 1, 2)
MsgBox, % "R1=" R.1 "`nR2=" R.2
return
exchangekeys(o, A, B)
{
m := o[A], o[A] := o[B], o[B] := m
}
Code: Select all
q:: ;test object get key addresses
obj := []
obj.1 := "1"
obj.2 := "2"
obj.3 := 3
obj.4 := 4
MsgBox, % &obj
MsgBox, % &obj.1 ;doesn't work
MsgBox, % &obj.2 ;doesn't work
MsgBox, % obj.GetAddress(1)
MsgBox, % obj.GetAddress(2)
MsgBox, % obj.GetAddress(3) ;doesn't work (because not string values)
MsgBox, % obj.GetAddress(4) ;doesn't work (because not string values)
return
Thank you! It's very helpful.jeeswg wrote: ↑23 Feb 2019, 11:43Here's some code. Cheers.Code: Select all
q:: ;test assigning obj.key to variable obj := [] obj.1 := "a" var := obj.1 ;value of obj.1 is stored, not reference to obj.1 obj.1 := "b" MsgBox, % var ;a ;obj.1's value changed, but var's value didn't change R := [1, 2] MsgBox, % "R1=" R.1 "`nR2=" R.2 exchangekeys(R, 1, 2) MsgBox, % "R1=" R.1 "`nR2=" R.2 return exchangekeys(o, A, B) { m := o[A], o[A] := o[B], o[B] := m }
Users browsing this forum: Araphen, Descolada, Oblomov228 and 169 guests