Disclaimer: Advanced Tasker is a series of Tasker articles that go beyond the beginner’s guide, and that’s aimed at those who have full control over everything covered in the guide. In this article series, step by step instructions will not be provided, there won’t be any downloadable files, and questions that belong in the beginner’s guide will not be answered. The aim of these articles is to discuss ideas that can be implemented in many different ways, in many different projects- and that requires the ability to create things from scratch, not by following step by step guides.

That does however bring up another problem. Unlike arrays, variable’s aren’t ever empty. If they are empty, they contain their own name, and if you write a space to them to make them appear empty, well then they contain a space. That means that an entry with either the variable name or a space will show in your Menu element, and if you have static icons for each list item like I do, even the instance with the space will be visible- and it will be there in any case.

There’s a method to deal with this, and it’s luckily fairly straight forward. First off, you need to make sure a variable is never empty to where it contains its own name, but rather always contains a single space when “empty”. This just means you use Variable Set with a space instead of Variable Clear, and you can even use a single Variable Set action to set it to a space with an If condition for it matching its own name before you launch your scene, just in case.

When that’s done, you need to start launching your scenes like this:

Here’s what happens in the above screenshot:

First it creates the scene without displaying it, allowing for manipulation of scene elements

Then it uses Element Visibility to make sure the Menu element is visible, but only if the variable used in that element, %Gtodo, is at least two characters long

Then it uses another Element Visibility to hide the Menu element if the variable doesn’t contain at least two characters

Finally, it displays the scene

In other words, every time the scene launches, it checks to see if the variable used in the Menu element is more than a single character long. If it’s not, it’s likely because it contains only a single space, and then it just hides the entire Menu element. Problem solved! At least if your scene only displays the info, so that you launch it every time there data changes. Things are a bit more complicated if you’re…

Adding to the variable from within the scene

In that case this works, but it might require that you use Element Visibility actions elsewhere too, depending on your project. My todo list, for instance, has options to add to the lists in the scene, while the scene is active. But, if the list is empty, the entire Menu is invisible, which means that if I just add to the variable, it won’t show unless I also include the Element Visibility action to re-enable the Menu element after I add something to the variable.

I know this sounds complicated, but trust me, this method is much, much faster than the easy way out, which is to just live with the delay caused by global arrays. My todo list project has gone through multiple rewrites, and it currently uses this method for populating the list, and I can assure you that it’s much faster than using a global array. It’s more complicated, yes, but it’s all about adding a few more actions when you create the project so that it works better in the long run. I’ve used this for many months now, and it works perfectly.

On a related note, I should add that using a variable instead of an array does mean you need to compensate a bit when you’re actually editing the variable as well. For instance, you need to remember that Variable Split to convert a variable to an array only works if there’s at least two items in the variable. This is because you split the variable by a comma, and that comma is only there if there’s more than one item. A simple If condition to check if the variable actually contains a comma is an easy fix for this.

Another take on adding info to a variable is to simply skip arrays altogether. Using Variable Search Replace and Variable Set you can do a lot of what arrays are good at with variables directly, such as appending info and removing something out from the middle of them. Here’s a couple of examples from my todo list project:

The above screenshot shows a method for adding something to the end of a variable. What you don’t see from the above is that the second Variable Set has Append enabled, while the first one doesn’t. If %Gtodo doesn’t match ++, it means it’s a single character, likely a space, and it’s considered empty. In that case, it replaces the value of the variable with the data that is added, %itemtoadd, and gets rid of the space in the process. The alternative situation is if %Gtodo is longer than two characters, which means it’s not empty. In that case, it appends a comma followed by the new data, %itemtoadd, to the variable.

This means that if %Gtodo has a value “apples,bananas”, and %itemtoadd is “pears”, the resulting value of %Gtodo will be “apples,bananas,pears”. When fed as a single variable into a Menu element, it will list everything separated by a comma individually.

This screenshot on the other hand shows a way to actually edit an entry in the Menu element. This is part of a long tap task for my todo list scene, meaning that I can press and hold an item to edit it. The variable %tap_label is a built-in variable that contains the data from the Menu item you clicked, meaning that if the item you clicked was “bananas”, %tap_label will be “bananas”.

To make this work as an edit feature, it first pops up a Variable Query, where %tap_label is used to populate the text field with the info you’re editing. Once done, it performs a Variable Search Replace, replacing the old %tap_label with the info from the Variable Query.

The downside of this is that unlike doing this with an Array, you can’t stop it from replacing it anywhere it finds it. So if %tap_label is present several places, it will replace all of them. An example would be if the first item on the list is “apple”, and the second is “apple pie”. Editing the first item to “orange” would leave the list saying “orange” and “orange pie”.

These are just two examples of how to deal with the fallout from using a variable instead of a global array. The reason why I haven’t covered my last few versions of the todo list project in detail is quite simply that there’s a ton of things like this in there, in other words complex systems designed to work around issues in Tasker. It’s ironic, but even though it’s way more complicated, it’s also way, way faster.

]]>https://www.pocketables.com/2013/04/advanced-tasker-dealing-with-empty-variables-in-scene-menus.html/feed1075321Advanced Tasker: Circumventing speed issues with global arrays in menu scene elementshttps://www.pocketables.com/2012/12/advanced-tasker-circumventing-speed-issues-with-global-arrays-in-menu-scene-elements.html
https://www.pocketables.com/2012/12/advanced-tasker-circumventing-speed-issues-with-global-arrays-in-menu-scene-elements.html#commentsFri, 14 Dec 2012 21:32:21 +0000http://www.pocketables.com/?p=64393Disclaimer: Advanced Tasker is a new series of Tasker articles that go beyond the beginner’s guide, and that are aimed at

Disclaimer: Advanced Tasker is a new series of Tasker articles that go beyond the beginner’s guide, and that are aimed at those who have full control over everything covered in the guide. In this article series, step by step instructions will not be provided, there won’t be any downloadable files, and questions that belong in the beginner’s guide will not be answered. The aim of these articles is to discuss ideas that can be implemented in many different ways, in many different projects- and that requires the ability to create things from scratch, not by following step by step guides.

In part 7 of the beginner’s guide I mentioned that I already knew of ways to speed up my todo list, and that there might very well be a V3 of the list that was shown off in V2 form in that article. Well, a V3 has been made, so has a V4, and while I haven’t made a V5, I’ve made another “app” that improves on the system the same way that a V5 of the list would. I haven’t talked much about these improvements so far, because V2 was really the last version of the list that could in any way to crowbared into the “beginner” definition. With this new series, however, I can finally talk about what I’ve learned without having to explain each of the several hundred actions in detail.

The menu scene element is one of the most powerful tools in Tasker, assuming you know how to use it. It’s very dynamic, and allows you to create a simple interface for dealing with data in massive quantities. My todo list is just one example, a file browser another, and the before mentioned new “app” (it’s so weirdly specific to my situation that I won’t even bother explaining what it does) a third. Unfortunately, there’s one rather massive issue with the menu element: There’s no way to feed it a local array. Because it’s technically a separate entity from other task, and as such don’t fall within those tasks’ definition of “locale”, it requires a global array to populate it.

Global variables are much slower than local ones, because they have to be updated throughout Tasker when set. Since a global array is a collection of global variables, and an array often contain dozens of entries, the normally hardly noticeable difference is suddenly measured in seconds. Suffice it to say, you don’t want an app that takes tens of seconds to update a list. I tried making a global array based file browser once, and it was stupid slow. Thanks to some help from the community I was able to device a better way, and it’s that method that I’ve now taken much further.

The whole idea is to only work with an array when you’re in a local task, and store the contents of that array as a global variable when moving between tasks (or scene elements). By setting a variable to %array(), you’re creating a single variable that has each item from the array as a comma separated list, thus creating only a single global variable. That variable can then be used in the menu scene element, as that supports comma separated lists. So, instead of feeding the menu an array, you’re feeding it a single variable that contains the contents of an array. The resulting menu looks the same, with each item from the comma separated list (i.e. each array item) listed individually.

Of course, this leaves you with a single variable of data, which isn’t necessarily ideal for other uses. I’ve experimented quite a bit, and found that while it is technically possible to use Variable Search Replace or Variable Split as substitutes for Array Pop and Array Push, it’s far from ideal. The biggest issue I’ve had is with runaway spaces and line shifts, which have long ago climbed to the top of my list of most annoying Tasker issues. Because my todo list writes to text files, which appends a line shift at the end, I ended up with random line shifts all over the place. You can use Variable Search Replace to get rid of those if each item in your list is void of any spaces (like a list of URLs, but that method doesn’t work for things like todo lists, which have spaces that should be there.

Long story short, it’s much easier to work with arrays, so why not just do that? Each time you need to manipulate the contents of the list, simply copy the global variable that contains your list to a local variable, and split it by the comma. Splitting by a comma and setting a variable to %array() are opposites, so you can go back and forth between single variables and beautiful local arrays this way. Then you have a local array that you can use Pop and Push on, use individual variable tools on, run through For loops, and so on. Because the item number in the list will directly correspond to the resulting array number, you can still use the tap and selected variables generated by interacting with the list. Tap the third item on the list, and the contents can be found in %array(%tap_index). At the end of the task, simply put the edited local array back into a single global array, and your list should update as if it was using the array as a source.

The speed difference you’ll be seeing over using a global array is ridiculous, and you’re going to have to come up with a lot less weird fixes by using this method over trying to edit the global variable instead of converting back to a local array. V3 and V4 of my todo list uses the global variable editing system, which means it’s fast, but there’s a scary amount of workarounds for loose line shifts and empty variables in there. The other app I was talking about uses this new hybrid system that switches between local arrays and a global variable, and it’s just so much easier to set up. I have yet to make a V5 of my todo list system since there wouldn’t be any obvious advantages now that the workarounds are already in place, but it would likely cut a good 50 actions off the total for the entire project if I did.

]]>https://www.pocketables.com/2012/12/advanced-tasker-circumventing-speed-issues-with-global-arrays-in-menu-scene-elements.html/feed864393Advanced Tasker: User creates automatic voice based cookbook in Taskerhttps://www.pocketables.com/2012/12/advanced-tasker-user-creates-automatic-voice-based-cookbook-in-tasker.html
https://www.pocketables.com/2012/12/advanced-tasker-user-creates-automatic-voice-based-cookbook-in-tasker.html#commentsMon, 10 Dec 2012 14:39:11 +0000http://www.pocketables.com/?p=63844Disclaimer: Advanced Tasker is a new series of Tasker articles that go beyond the beginner’s guide, and that are aimed

Disclaimer: Advanced Tasker is a new series of Tasker articles that go beyond the beginner’s guide, and that are aimed at those who have full control over everything covered in the guide. In this article series, step by step instructions will not be provided, there won’t be any downloadable files, and questions that belong in the beginner’s guide will not be answered. The aim of these articles is to discuss ideas that can be implemented in many different ways, in many different projects- and that requires the ability to create things from scratch, not by following step by step guides.

Processing data in Tasker can be used for a lot of things. After all, most of the apps we use and love on our devices deal with various ways of pushing text around, be it an ebook reader, email client, social media service, or a shopping list. Coming up with new ideas for projects can be hard, but sometimes you end up with something that is such an obviously useful thing to have. That’s exactly what one of our commenters, “Mike,” did when he created an interactive voice based cookbook using Tasker, and shared it with us in the comments to another article.

The system is designed to provide a fully hands-free approach to cookbooks. With a user-created recipe selected, Tasker will read sections of the recipe using Text To Speech. It will then wait a predefined amount of time to let the actual cook follow the instructions, and then ask if it should continue, stop, or repeat. Each recipe is created using text files formatted in a specific way, and the time to wait between each section is naturally decided by the user. This both eliminates the need to handle a mobile device while cooking, and the need to use timers.

Everything you need to build your own version of this is mentioned in our beginner’s guide to Tasker. Mike’s version starts by having a index text file that gets read into a scene menu, with the file paths to the actual recipes tied to the recipe titles. That way you start off by having an actual menu to select recipes. Each recipe file is formatted in a way that makes it easy to split out each section and the duration of it using standard variable handling actions. You can then use a For loop to have a dynamic way to handle each section, going through the motion of splitting and reading information, waiting, and asking to proceed for each array element you get from the initial split into sections.

There is also a lot of potential for adding more features to this. Mike is already working on a way to pause and resume the recipe, as well as a way to integrate interactive elements within each section. An example of the latter, to use the one Mike posted, is to have the system ask to set an actual timer for 60 minutes if a mention of that is encountered in the recipe. Just to list some potential features I can think of myself for this, you could have smartwatch-integration (if you have one of those), a shopping list system that would let you view a list of ingredients for a recipe in a menu you could cross off (without affecting the actual recipe of course), potentially use a Bluetooth speaker with microphone and leave the device in another room (Tasker’s Bluetooth features are a bit sketchy at the moment), or even have images of each step automatically show on the screen- which would work great on a tablet.

There’s a lot of possibilities here, and it’s an awesome idea to begin with. I rarely cook anything that requires a recipe myself, but I can see how this would come in handy, and even be the device-defining feature for some. Best of all, it uses relatively simple methods to achieve the goal, it just uses them in clever ways. Great job Mike!