Can a VarRef be assigned a new value? Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
iseahound
Posts: 1582
Joined: 13 Aug 2016, 21:04
Contact:

Can a VarRef be assigned a new value?

08 Dec 2021, 22:55

I'm not sure if I'm looking the right places within the documentation:
A VarRef can be used to assign to the original target variable or retrieve its value by dereferencing it.
So how can a VarRef be assigned a new value?

Code: Select all

var := 123
fn(&var)
MsgBox var

fn(var) {
   ; check if a varref is passed, and if so change the value
   if IsSetRef(var)
       ; assign a new value to the varref
   ; otherwise return the different value.
}
Edit: In case this question is not clear, using fn(&var) => (var := 456) is not the solution I am looking for. I am asking whether the VarRef object contains some "value" parameter that can be directly set. Using ObjOwnProps to inspect a VarRef object fails, as it shows "expected an object not a varref" or something like that.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Can a VarRef be assigned a new value?

09 Dec 2021, 02:57

Code: Select all

if IsSetRef(var)
       %var% := '; assign a new value to the varref'
iseahound
Posts: 1582
Joined: 13 Aug 2016, 21:04
Contact:

Re: Can a VarRef be assigned a new value?  Topic is solved

09 Dec 2021, 15:38

I swear I tried that. Thanks!

Code: Select all

var := 123
fn(&var)
MsgBox var

fn(var) {
   if IsSetRef(var)
      %var% := 456
}

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: DavidP, mikeyww and 76 guests