Export global variables

Post your feature requets for new triggers, conditions, actions and other improvements.

Moderator: Martin

User avatar
TheBrain1984
Posts: 137
Joined: 07 Aug 2013 08:17
Location: Germany

Export global variables

Post by TheBrain1984 » 04 Nov 2014 01:15

Hi,

it would be great, if I can export the global variables like the flows and the widgets. My cellphone crushed two times now and I could restore a backup of my flows and my widgets but the global variables were lost.

Thanks a lot.

Regards
Manuel

User avatar
MURTUMA
Posts: 697
Joined: 05 Mar 2013 22:43

Re: Export global variables

Post by MURTUMA » 04 Nov 2014 12:21

While the global vars are saved "infinitely" they are not meant to permanently save data. At least, as far as I've understood.

You can create a flow which collects all your global vars and writes them to a file on a regular basis. In case of crash and vars being lost, you could read the file with Automagic and save them again as variables. I'm sorry, I can't help you do that considering my knowledge of scripting, but that is a general idea of a one way how you can backup those.

mcyber
Posts: 37
Joined: 08 Nov 2013 14:21

Re: Export global variables

Post by mcyber » 07 Nov 2014 13:28

MURTUMA wrote:While the global vars are saved "infinitely" they are not meant to permanently save data. At least, as far as I've understood.

You can create a flow which collects all your global vars and writes them to a file on a regular basis. In case of crash and vars being lost, you could read the file with Automagic and save them again as variables. I'm sorry, I can't help you do that considering my knowledge of scripting, but that is a general idea of a one way how you can backup those.
Indeed they are, at least in some situations.

Besides the backup use case, this feature would let you easily duplicate flows that rely on some "permanent" settings to another device. Especially if some variables are lenghty multi-dimansional maps or lists. I have 2 devices (phone and tablet). My programming style tends to favor generic structures that are instantiated at runtime. One example are nested menus. You need a single flow to manage all the menus, from the topmost to the last: the only thing you need to manage is a list of lists, or a map of maps, containing text for the options, some paramaters to initialize the menu interface, such as a default value, and some data to manage the resulting choice (i.e. calling a flow, set a variable value, call another menu, launch an app,... - I only call flows and set variables). I use some of these "permanent" structures and it's a pain to type all these infos from one device to the other and the procedure is potentially error prone, especially during the initial setup. On the other side, and only in my opinion, it is not worth the effort to setup a flow to create this kind of variables, nor it is to create a text file and parse it.

You're right, though, that some or most of globals are pure runtime states, that describe the "system" at a specific time and/or in specific condtions. The possibility to select which variables are worth exporting solves the issue (much like as when exporting flows).

I think it would be a time saver.

Export Global Variables += 1.

User avatar
kintrupf
Posts: 257
Joined: 10 Sep 2013 08:59

Re: Export global variables

Post by kintrupf » 07 Nov 2014 13:50

mcyber wrote:One example are nested menus. You need a single flow to manage all the menus, from the topmost to the last: the only thing you need to manage is a list of lists, or a map of maps, containing text for the options, some paramaters to initialize the menu interface, such as a default value, and some data to manage the resulting choice (i.e. calling a flow, set a variable value, call another menu, launch an app,... - I only call flows and set variables).
That sounds quite interesting! Building extensive menus and responding to the choices is a chore with Automagic, could you post an example of your solution?

mcyber
Posts: 37
Joined: 08 Nov 2013 14:21

Re: Export global variables

Post by mcyber » 13 Nov 2014 13:28

kintrupf wrote:
mcyber wrote:One example are nested menus. You need a single flow to manage all the menus, from the topmost to the last: the only thing you need to manage is a list of lists, or a map of maps, containing text for the options, some paramaters to initialize the menu interface, such as a default value, and some data to manage the resulting choice (i.e. calling a flow, set a variable value, call another menu, launch an app,... - I only call flows and set variables).
That sounds quite interesting! Building extensive menus and responding to the choices is a chore with Automagic, could you post an example of your solution?
Hi kintrupf. I'm sorry not to have replied earlier. I'm a bit busy with my job. Please be patient, and I'll post the requested solution. I need to build a working skeleton with simple menus, that could be easily expanded. I need also to find a way to build the needed variables, maybe statically, within a flow, otherwise, if I'd supply my flows without a proper explanation, I fear I'll have to answer to many questions from users. So it will take a bit, not that much, but a bit.

Keep in touch, I'll do it.

User avatar
kintrupf
Posts: 257
Joined: 10 Sep 2013 08:59

Re: Export global variables

Post by kintrupf » 13 Nov 2014 13:38

No problem, I can wait :D

User avatar
Bushmills
Posts: 286
Joined: 23 Sep 2014 21:56

Re: Export global variables

Post by Bushmills » 13 Nov 2014 13:49

I could think of this solution: Assuming that you're not creating the global variables which you wish to export manually, there will be a flow action (probably a script) creating them by assigning a value to the global variable.

At this point, add code to test whether the name of the variable is element in a list of variable names, and, if it isn't, add the name to the list. This is a one-liner.

At strategic points in your flows (periodically, upon assignment, or before shutdown, maybe a combination), run through that list, and write list elements as "name = value;" to a file. When Automagic starts, eval contents of that file.

Untested, just conceptional. All required components available, as far as I can see.

Were variables, or just global variables, organised in a map ( name -> value ) by Automagic, so they can be referenced other than by name, the need to add them to a list yourself would evaporate.

User avatar
TheBrain1984
Posts: 137
Joined: 07 Aug 2013 08:17
Location: Germany

Re: Export global variables

Post by TheBrain1984 » 14 Jan 2015 18:47

Is there a var that hold all global vars so that I can do a for-loop for all global vars to write them into a file if necessary?

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Export global variables

Post by Martin » 14 Jan 2015 20:37

No, there's no such variable yet. I can add a function to get the variable names in the next version of Automagic.

User avatar
TheBrain1984
Posts: 137
Joined: 07 Aug 2013 08:17
Location: Germany

Re: Export global variables

Post by TheBrain1984 » 16 Jan 2015 06:06

Thanks

Locked