varying variable name for "set variable" action?

420

Active member
i don't know if what i am looking for exists, or if i should post in the feature requests section?


when i add an action "set variable" i have to pick a fixed variable name, but instead i want to type it out so the variable can include variables, if that makes any sense.

so instead of the set variable action being:

"set variable M1D1 to [variable-A]"

i want it to be like this:

"set variable M[variable-B]D[variable-C] to [variable-A]"

in my case [variable-B] and [variable-C] can be at any number between 1-7,
so if theres a way to do this i can just use 1 set variable action, instead of having to create 49 different if clauses and set variable actions.
 

dsnz

Well-known member
hmm .. you ask what's called "indirect addressing" 😂
I think you try to simulate arrays

unfortunately I don't know a good workaround for this :(
 

FrameXX

Well-known member
Really good idea that would improve flexibility. Same would be good for stopwatches.

For example start stopwatch named
"[MyVariable]"
Pause stopwatch named
"app [MyVariable]"
 

dsnz

Well-known member
I have created a workaround to OP's request

it's a workaround in the sense that it doesn't store values in macrodroid variables but can still be used effectively in macros

this solution uses two global variables

var_name which contains the variable name we want to use

for the OP's example this can be set to be

M[lv=B]D[lv=A]

and by setting global variable

var_value

and calling macro "var_set" we set the value for this variable (we don't save it in macrodroid but we save the value of variable with name in var_name outside macrodroid, in a file actually using shell commands)

and we can get it again

by calling macro "var_get" (this gets the saved value for variable with name in var_name)

the code for these macros is very simple and is shown below
 

Attachments

  • var_set.png
    var_set.png
    41 KB · Views: 27
  • var_get.png
    var_get.png
    38.5 KB · Views: 27

FrameXX

Well-known member
I have created a workaround to OP's request

it's a workaround in the sense that it doesn't store values in macrodroid variables but can still be used effectively in macros

this solution uses two global variables

var_name which contains the variable name we want to use

for the OP's example this can be set to be

M[lv=B]D[lv=A]

and by setting global variable

var_value

and calling macro "var_set" we set the value for this variable (we don't save it in macrodroid but we save the value of variable with name in var_name outside macrodroid, in a file actually using shell commands)

and we can get it again

by calling macro "var_get" (this gets the saved value for variable with name in var_name)

the code for these macros is very simple and is shown below

Really cool! Thank you!
 
Top