Export global variables
Moderator: Martin
- TheBrain1984
- Posts: 137
- Joined: 07 Aug 2013 08:17
- Location: Germany
Export global variables
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
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
Re: Export global variables
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.
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.
Re: Export global variables
Indeed they are, at least in some situations.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.
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.
Re: Export global 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 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).
Re: Export global variables
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.kintrupf wrote: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 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).
Keep in touch, I'll do it.
Re: Export global variables
No problem, I can wait 

Re: Export global variables
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.
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.
- TheBrain1984
- Posts: 137
- Joined: 07 Aug 2013 08:17
- Location: Germany
Re: Export global variables
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?
Re: Export global variables
No, there's no such variable yet. I can add a function to get the variable names in the next version of Automagic.
- TheBrain1984
- Posts: 137
- Joined: 07 Aug 2013 08:17
- Location: Germany
Re: Export global variables
Thanks