Page 1 of 1

Best way to initialize global variables?

Posted: 12 Sep 2017 14:27
by Bluscre
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 ;)

Re: Best way to initialize global variables?

Posted: 12 Sep 2017 16:13
by Desmanto
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.