Why global variable can't be used as a function argument?

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
beelze
Posts: 46
Joined: 04 Nov 2018 16:45

Why global variable can't be used as a function argument?

Post by beelze » 06 Nov 2018 06:49

I'm new in AM, so maybe I just missing a some vital concept, but here's a problem:

Tried to use condition expression like

Code: Select all

matches(join(somelist, ","), global_var)
but it always evaluates as false (global_var is a string ".*text").

But putting the same regex as string literal:

Code: Select all

matches(join(somelist, ","), ".*text")
working as expected. I'm puzzled :shock:

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Why global variable can't be used as a function argument

Post by Desmanto » 07 Nov 2018 02:09

I can replicate your problem once. The global_telkampret (I have created after Automagic 1.36.0), change it to string .*text. And suddenly it changes itself to number 1 after the script execution. Don't know why. After assigning the value directly in script

Code: Select all

global_telkampret = ".*text";
matches("hello,adsf,text", global_telkampret);
use that directly, it works. But if I comment that line (since the glovar has been saved), again, it changes itself to 1 after execution.

Assigning temporary variable to it also doesn't matter.

Code: Select all

a = global_telkampret;
matches("hello,adsf,text", a);
This still produce the same error, global_telkampret changes to 1 after execution.

However using the exact same script but with global_widget, same string type, no problem at all. global_widget was created long long time ago. So it seems something is off with the glovar creation.

Then I just remembered I have used this glovar somewhere, not a temporary glovar anymore. And yes I used it in a working flow as the marking for state :D The script change the glovar to 1 when it change to something else. Hence explained the mysterious behaviour. You should search for the global_var in your flow and see if there something changing it to another thing.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
beelze
Posts: 46
Joined: 04 Nov 2018 16:45

Re: Why global variable can't be used as a function argument

Post by beelze » 07 Nov 2018 07:45

Your guess was close.

Autocorrection has corrected <.> to <. >, which was not noticeable before I catched it in log :-)

Post Reply