Ability to reference a variable with another variable's value

vyros4u

New member
Let say I have a variable integer name [count] and another variables ([var1] , [var2] , [var3], [var4] .. ) I will like to refer these variables by substituting the digit in the name with value of [count]
Eg. If [count]=2 [var[count]] in this case the value of count determines the respective [var] value
In this if I want select one of [var..] I don't hv to use so many ifs and elseif

I hope this will be useful and handy
 
Last edited:

Abalsam

Active member
You might not be able to do it directly but you could do it with either an if action or a constrained action. In other words:

If count=1 set var to var1
If count=2 set var to var2

Etc.
 

tanutanu

Well-known member
Let say I have a variable integer name [count] and another variables ([var1] , [var2] , [var3], [var4] .. ) I will like to refer these variables by substituting the digit in the name with value of [count]
Eg. [var[count]] in this case the value of count determines the respective [var] value
In this if I want select one of [var..] I don't hv to use so many ifs and elseif

I hope this will be useful and handy
Well, It had been implemented, could be extracted when the inner [count] value incremented. I use the similar technique in some macros and action blocks. It is working correctly:)
 

Attachments

  • IMG_20220118_220548.jpg
    IMG_20220118_220548.jpg
    324.2 KB · Views: 5
  • IMG_20220118_220644.jpg
    IMG_20220118_220644.jpg
    93 KB · Views: 6
  • IMG_20220118_222122.jpg
    IMG_20220118_222122.jpg
    101.3 KB · Views: 5
  • IMG_20220118_222046.jpg
    IMG_20220118_222046.jpg
    380.4 KB · Views: 5

vyros4u

New member
Let say [var1, var2, var3, var4] has their respective values and [count] is an integer, calling either value of [var1, var2, var3] without using too many ifs by doing var[count]
 

tanutanu

Well-known member
Let say [var1, var2, var3, var4] has their respective values and [count] is an integer, calling either value of [var1, var2, var3] without using too many ifs by doing var[count]
"temp = [lv=val[lv=count]]" is working as well. The point is that the nested magic text extraction in the MD variable is implemented and you can make array-ish string variable:)
 

Attachments

  • IMG_20220118_223941.jpg
    IMG_20220118_223941.jpg
    188.9 KB · Views: 9
Last edited:

420

Active member
Let say I have a variable integer name [count] and another variables ([var1] , [var2] , [var3], [var4] .. ) I will like to refer these variables by substituting the digit in the name with value of [count]
Eg. If [count]=2 [var[count]] in this case the value of count determines the respective [var] value
In this if I want select one of [var..] I don't hv to use so many ifs and elseif

I hope this will be useful and handy
I had a similar question some time ago (atleast i think you are wanting the same thing), maybe you can find something helpfull there, forum member dsnz has posted a workaround in that thread: https://www.macrodroidforum.com/index.php?threads/varying-variable-name-for-set-variable-action.417/
 

tanutanu

Well-known member
I had a similar question some time ago (atleast i think you are wanting the same thing), maybe you can find something helpfull there, forum member dsnz has posted a workaround in that thread: https://www.macrodroidforum.com/index.php?threads/varying-variable-name-for-set-variable-action.417/
ah, I missed it;)
Well the variable name replacement(even a part), can do with string variable:) Of course, it is good alternative to be stored in a file👍
I prefer to assign in a string even linear array or map(hash/dict) data type structure itself, multi dimensional is annoying though:(
 
Top