Local or global in set variable magic text

sneike

New member
Screenshot_20220819-103755_MacroDroid.jpg

In the screenshot above:
"iteration-num" is an integer and I want to set it as the array size of a dictionary global variable
"scelta" is a string-type global variable
"scelta-local" is a string-type local variable

When I set iteration-num I have to manually write the magic text because it doesn't show me devicesOPTIONS in the list of variables, I don't know why.

If I set:
iteration-num:{size=devicesOPTIONS[{v=scelta}]}
I'm not allowed to press OK when creating the action.

Screenshot_20220819-124439_MacroDroid_2.jpg

To make it work I need to create an extra local variable and use that as the dictionary key index.

Why is that?

Thanks
 

Endercraft

Moderator (& bug finder :D)
View attachment 3238

In the screenshot above:
"iteration-num" is an integer and I want to set it as the array size of a dictionary global variable
"scelta" is a string-type global variable
"scelta-local" is a string-type local variable

When I set iteration-num I have to manually write the magic text because it doesn't show me devicesOPTIONS in the list of variables, I don't know why.

If I set:
iteration-num:{size=devicesOPTIONS[{v=scelta}]}
I'm not allowed to press OK when creating the action.

View attachment 3239

To make it work I need to create an extra local variable and use that as the dictionary key index.

Why is that?

Thanks
I don't think that's a feature yet.
 

Dm114

Well-known member
View attachment 3238

In the screenshot above:
"iteration-num" is an integer and I want to set it as the array size of a dictionary global variable
"scelta" is a string-type global variable
"scelta-local" is a string-type local variable

When I set iteration-num I have to manually write the magic text because it doesn't show me devicesOPTIONS in the list of variables, I don't know why.

If I set:
iteration-num:{size=devicesOPTIONS[{v=scelta}]}
I'm not allowed to press OK when creating the action.

View attachment 3239

To make it work I need to create an extra local variable and use that as the dictionary key index.

Why is that?

Thanks
When writing an expression, it is evaluated with the current values at writing time. The OK button will be enabled if the evaluation is possible.

What I often have to do in such situation is to run the macro and stop it (Cancel) just before the litigious action. Then configure it with the appropriate terms in the expression (with values loaded at this step).
 

sneike

New member
When writing an expression, it is evaluated with the current values at writing time. The OK button will be enabled if the evaluation is possible.

What I often have to do in such situation is to run the macro and stop it (Cancel) just before the litigious action. Then configure it with the appropriate terms in the expression (with values loaded at this step).
True, I already noticed that and I do the same thing. I make sure my variables are populated before writing the expression with magic text.

In this case "scelta" is a global variable and it has already the value I am interested in when I write the expression. Maybe the evaluation when writing the expression cannot access global variables? Or maybe it's just a bug of some sort?
 

Dm114

Well-known member
True, I already noticed that and I do the same thing. I make sure my variables are populated before writing the expression with magic text.

In this case "scelta" is a global variable and it has already the value I am interested in when I write the expression. Maybe the evaluation when writing the expression cannot access global variables? Or maybe it's just a bug of some sort?
Are you sure devicesOPTIONS[{v=scelta}] is a dictionary and not a string or numerical variable because size applies to a whole dictionary/array?
 

sneike

New member
Are you sure devicesOPTIONS[{v=scelta}] is a dictionary and not a string or numerical variable because size applies to a whole dictionary/array?

100% sure:

Screenshot_20220819-163730_MacroDroid.jpg

Demonstration that the expression is correct, is that if I set local variable scelta-local:{v=scelta}, and I use {size=devicesOPTIONS[{lv=scelta-local}]}, it works properly. but {v=scelta} and {lv=scelta-local}, are exactly the same string, but with the global variable it doesn't work, with the local variable it does.

Screenshot_20220819-103755_MacroDroid.jpg
 

Endercraft

Moderator (& bug finder :D)
100% sure:

View attachment 3240

Demonstration that the expression is correct, is that if I set local variable scelta-local:{v=scelta}, and I use {size=devicesOPTIONS[{lv=scelta-local}]}, it works properly. but {v=scelta} and {lv=scelta-local}, are exactly the same string, but with the global variable it doesn't work, with the local variable it does.

View attachment 3241
Maybe using a global dictionary works ?
It's probably just a bug.
 

Dm114

Well-known member
100% sure:

View attachment 3240

Demonstration that the expression is correct, is that if I set local variable scelta-local:{v=scelta}, and I use {size=devicesOPTIONS[{lv=scelta-local}]}, it works properly. but {v=scelta} and {lv=scelta-local}, are exactly the same string, but with the global variable it doesn't work, with the local variable it does.

View attachment 3241
Do you need to use local or global variable as key? I noticed that, when using dictionaries/arrays and renaming an existing local variable, it is sometimes transformed to a global one and names are messed up.Then I delete both variables (global and local) and recreate the only one I need...
 

sneike

New member
Do you need to use local or global variable as key? I noticed that, when using dictionaries/arrays and renaming an existing local variable, it is sometimes transformed to a global one and names are messed up.Then I delete both variables (global and local) and recreate the only one I need...
I need that to be a global variable.
 

Dm114

Well-known member
I need that to be a global variable.
Really strange behavior indeed!

I would suggest to delete both variables (local and global), then create the global one you need and reboot your device.

If it still doesn't work with the global variable alone, create a local one again, load global variable content to this new local variable and try to get the dictionary entry with this local variable as key.

If it still works this way and still doesn't with the global variable alone as key, report the bug with the Troubleshooting section in the MacroDroid main menu...
 

MacroDroidDev

Administrator
Staff member
View attachment 3238

In the screenshot above:
"iteration-num" is an integer and I want to set it as the array size of a dictionary global variable
"scelta" is a string-type global variable
"scelta-local" is a string-type local variable

When I set iteration-num I have to manually write the magic text because it doesn't show me devicesOPTIONS in the list of variables, I don't know why.

If I set:
iteration-num:{size=devicesOPTIONS[{v=scelta}]}
I'm not allowed to press OK when creating the action.

View attachment 3239

To make it work I need to create an extra local variable and use that as the dictionary key index.

Why is that?

Thanks

The expression looks incorrect. You should not be write something like size= in here. Instead you should be selecting the size variable when configuring the action and then setting it to the value in the expression (only the desired value should be written in the expression box).
 

sneike

New member
The expression looks incorrect. You should not be write something like size= in here. Instead you should be selecting the size variable when configuring the action and then setting it to the value in the expression (only the desired value should be written in the expression box).
Not sure I understand what you mean. I'll try to explain my points as best as I can.

- When I create the "set variable" action, I select my integer local variable I want to set, then click on "expression" and the 3 dots for the magic text. If I select the "dictionary/array size" it only shows my local dictionaries/arrays. Why it doesn't show global ones?

- Let's say I select a local dictionary, in the text field I will see {size=dict-local[example-key]}. dict-local[example-key] is also a dictionary.

- but since I want to use a global dictionary, I will manually replace the text with {size=dict-global[example-key]}. And this still works.

- last step is that I want the key of the dictionary to be the value of a variable. If I use the three dots magic text, in the menu I can't see any string variable (I suppose it's because I'm setting an integer variable), so I'll write it manually and my expression becomes {size=dict-global[{lv=local-key}]}. This works, the OK button is enabled and the macro works.

- but it's not over yet, because I want the key to be the value of a string GLOBAL variable. As usual I can't use the magic text menu so I'll write the expression like this {size=dict-global[{v=global-key}]}. Values of local-key is the same as global-key, but this expression is not accepted and I can't press the OK button as shown in the first post in this topic.

I hope this explanation helps. Let me know what you think.

Thanks
 

MacroDroidDev

Administrator
Staff member
Sorry I think I misunderstood what was originally written.

I've just recreated the missing global variables issue and this is just a plain and simple bug so I will make sure it's fixed soon.
 
Top