1

I'm trying to learn Tasker, and it seems that it runs its steps asynchronously, so I end up with a race condition where my task doesn't have the data it needs to continue. I made a simple pair of tasks to test. (Hardware info: LG G2 on Verizon running stock KitKat ROM, rooted.)

Task 1: Echo

  1. Variable Set: [Name: %ret; To: %par1]
  2. Flash: [Text: Par1 = %par1]
  3. Return: [Value: %ret; Stop: On]

Task 2: Echo Test

  1. Perform Task: [Name: Echo; Priority: 2; Parameter 1 (%par1): 5; Return Value Variable: %var]
  2. Variable Set: [Name: %dbl; To: %var * 2; Do Maths: On]
  3. Flash: [Text: %var * 2 = %dbl]

Expected output:

  1. Flash: "Par1 = 5"
  2. Flash: "5 * 2 = 10"

Actual output:

  1. Flash: "%var * 2 = 0"
  2. Flash: "Par1 = 5"

My question is, why doesn't Tasker wait for step 1 to complete before continuing on to step 2? In fact, I'm not even sure it's working correctly in the first place. In my Echo Test task, I added a 2-second wait after calling the Echo task, and now my output is this:

  1. Flash: "Par1 = 5"
  2. Flash: "%var * 2 = 0"

So the %var variable doesn't seem to get set at all. Am I doing something wrong, or is my Tasker installation bad?

3

There are 2 potential solutions.

One, when you use "Perform Task", you can pick the priority of the task you're asking it to run. If you set the priority the same or higher than the current task (a good way to do this is to specify %priority + 1), the new task will completely execute before the current on resumes. If you set the priority of the task lower than the current task's priority, the current task will finish before the new task starts.

Since I've had mix results with the use of priority, you could add a "Wait Until" after the perform task. Example:

1. WAIT UNTIL
      MIN: 1
      UNTIL: %Done IS SET

The variable, %Done, is set at the last line of the task you called. You can set %Done to anything but one it is set the 1st task will know it is okay to continue.

  • It turns out Priority was the culprit. Thanks. Sorry, I can't upvote yet -- I'm too new myself. – howcheng Jul 8 '14 at 17:11
  • Great answer. I use the priority+1 frequently, but I like the additional suggestion of using wait until if you have a situation where you need to be sure. – Wyzard Aug 25 '14 at 2:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.