Can you execute a task from within a task?

6,014 views
Skip to first unread message

PaulQ

unread,
Aug 15, 2012, 3:23:13 AM8/15/12
to tas...@googlegroups.com
I'd like to execute a task from within another task. Is that possible?

Thanks!

Rarry

unread,
Aug 15, 2012, 3:31:16 AM8/15/12
to tas...@googlegroups.com


From the documentation:


Subroutines

To call another task, use the Perform Task action. To use it as a subroutine, you just need to ensure that the priority of the calling task is less than the priority of the called task (more info: scheduling).

The parent can optionally pass values to the child and receive a result back:

Parent Task

1.  Perform Task 
Child, 
Priority, 10 
%par1, 5, 
Result Value Variable, %result
pass 5 to the child, expect a result in %result
2.  Variable Flash
Result: %result
what did we get back ?

Child Task

1.  Variable Set 
%newval, %par1 + 1, Do Maths
add one to the value that was passed
1.  Return
%newval 
set %result in the parent to the value of %newval in the child

Result: the parent flashes 6

Notes:

  • changes made to %par1 and %par2 in the child task are not reflected by their changing in the parent task
  • receiving a return value is optional for the parent, even if the child tries to give it one
  • unlike Return statements in most computer languages, Tasker's does not necessarily stop the child task, so if the child and parent have the same priority they can both run together and the child return several results over time.

Vladimir Oz

unread,
Aug 15, 2012, 3:49:44 AM8/15/12
to tas...@googlegroups.com
Smth to add
You can exec task from itself and make recursion. Just enable running for both (or more) instances.

Pent, noobs still don't read man. It's only for advanced users :) I think You should make and pick up thread "Read man before ask here".... Sure, I remember about users loyalism 

Pent

unread,
Aug 15, 2012, 4:16:31 AM8/15/12
to Tasker

> You should make and pick up thread "Read man before ask here"....

Used to exist, didn't have any effect.

Pent

PaulQ

unread,
Aug 15, 2012, 2:46:23 PM8/15/12
to tas...@googlegroups.com
It's not an issue of not reading. I am aware of that documentation. I was hoping to get a more "noob-friendly" explanation. I can usually figure this stuff out with some time. I have gotten Tasker to do quite a bit now over time and exploration/experimentation. I'll have to spend some time with those instructions now.

Wietse van Buitenen

unread,
Jan 12, 2013, 4:20:28 AM1/12/13
to tas...@googlegroups.com, qat...@gmail.com
in the Perform Task you have an option called Priority..?.
When you long-press a Profile and choose Properties you can set the initial Launched Task Priority

On Saturday, January 12, 2013 7:08:32 AM UTC+1, LameName90210 wrote:

 My project has a MAIN task, which calls a series of sub-tasks.

The documentation says: "
To call another task, use the Perform Task action. To use it as a subroutine, you just need to ensure that the priority of the calling task is less than the priority of the called task"

However, I can't see where to set the priority of each task?

LameName90210

unread,
Jan 12, 2013, 10:08:16 PM1/12/13
to tas...@googlegroups.com, qat...@gmail.com

 Thanks. It's working better now. I can see alerts appearing which proves my MAIN task is successfully calling the "Take Photo" sub-task four times.

 However, for some reason the "Take Photo" task only takes one photo (the first one) but doesn't take the other 3 photos.

 I've unchecked the STOP command in each of the Perform Task calls. 

 Not sure why the same task runs successfully once and then doesn't take a photo the next three times.  Hmmm...





 

Richard Davis

unread,
Jan 12, 2013, 10:55:50 PM1/12/13
to tas...@googlegroups.com


>  Not sure why the same task runs successfully once and then doesn't take a photo the next three times.  Hmmm...

To check the flow you can turn on the run log and check it -- menu / more / run log

You might just need a wait in-between the perform tasks. 

Rich...

LameName90210

unread,
Jan 13, 2013, 1:05:00 AM1/13/13
to tas...@googlegroups.com

Thanks Rich.

The run log looked good, so I inserted a 30-second wait task between each perform task and it worked perfectly, taking FOUR photos as expected.
Now I'll either (a) reduce the wait duration to limit the delay OR preferably,  (b) try to make it wait until the sub-task isn't running.  There's a command for listing the active tasks, I believe.

Cheers. 



Richard Davis

unread,
Jan 13, 2013, 8:05:19 AM1/13/13
to tas...@googlegroups.com

> Now I'll either (a) reduce the wait duration to limit the delay OR preferably,  (b) try to make it wait until the sub-task isn't running.  There's a command for listing the active tasks, I believe.
>

The problem is the sub tasks are going to fast for the camera app, so
I think it will have to be 'a'.  Or perhaps some test to see when a new file has been added to your DCIM/CAMERA file...

Rich.....

TomL

unread,
Jan 13, 2013, 8:59:45 AM1/13/13
to tas...@googlegroups.com
Maybe you can watch for %FOTO to change.

So something like this:

set add var %taken plus 1
set var %local to %FOTO
take photo
stop if %taken > 3
while %local doesn't equal %FOTO, wait 1 second
goto action 1

TomL

unread,
Jan 13, 2013, 9:09:01 AM1/13/13
to tas...@googlegroups.com
Ack, sorry, bug. The while line should read

while %local = %FOTO, wait 1 sec

Tom

LameName90210

unread,
Jan 28, 2013, 12:53:34 AM1/28/13
to tas...@googlegroups.com, qat...@gmail.com

Thanks Tom and Rich!

Reply all
Reply to author
Forward
0 new messages