Page 1 of 1

A more elegant way to get variables dynamically

Posted: 01 Mar 2023, 11:48
by crocodile
The current method is

Code: Select all

t:="A_Args"

if isset(%t%)
	out := %t%
Can we add a function to get the variable from the string? e.g. out := getvar(t)

Re: A more elegant way to get variables dynamically  Topic is solved

Posted: 02 Mar 2023, 09:39
by Descolada
I don't see why that would be necessary. If you want to assign the value of %t% to out, but choose a default value (e.g. "") if it's unset, you can use out := %t% ?? "". Or perhaps define a function that does that: Deref(var, default:="") => %var% ?? default. If you don't want to use a default value, then you just push your impending "unset variable" error further down the line:

Code: Select all

if isset(%t%)
	out := %t%
if %t% evaluates to unset, then out will be unset, and once you try to access it you will get an error (instead of getting it right away with %t%.

Re: A more elegant way to get variables dynamically

Posted: 04 Mar 2023, 07:05
by crocodile
Thank you. I ignored this new command.