Best way to initialize global variables?

General discussions about Automagic and automation in general

Moderator: Martin

Post Reply
User avatar
Posts: 142
Joined: 31 Aug 2017 13:58
Location: Germany

Best way to initialize global variables?

Post by Bluscre » 12 Sep 2017 14:27

There are several ways to set Variables and i want your opinion which one's the best. If you know of any other way i forgot, please tell me and i add it :^)
  • Code: Select all

    convertNull(global_variable, newList("default", "values"));
  • Code: Select all

    if (global_variable == null) { global_variable = false; }
@Desmanto, @Martin looking forward to your pro opinions ;)
Unofficial AutoMagic Telegram Group:
Check out my other flows here: or here.
Sent from my Lenovo TAB 2 A10-70L running Android 6.0.

User avatar
Posts: 2476
Joined: 21 Jul 2017 17:50

Re: Best way to initialize global variables?

Post by Desmanto » 12 Sep 2017 16:13

I just go to the global variable and create the GloVar there :D Just kidding :)

I use also the same, with slight different style

Code: Select all

if(global_variable == null)
  global_variable = false;
For single line script after if() with no else, we can remove the curly braces.

Be careful thought, sometimes empty GloVar doesn't always mean it is null. Sometimes it is '' (two single quote). If it is that case, convertNull() will fail, global_variable == null also give false. It should be global_variable == '' which gives true.
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.

Post Reply