Goto Top of Loop causing endless loop instead of continue to the next iteration?

89 views
Skip to first unread message

Ivelin Ivanov

unread,
Jun 9, 2013, 1:19:44 PM6/9/13
to tas...@googlegroups.com
I'm trying to make a profile that disables all enabled profiles but a few selected ones, but the Goto action in one of the loops causes an endless loop:

Profile: Stealth Mode (13)
State: Variable Value [ Name:%Theft_Detected Op:Matches Value:1 ]
Enter: Anon (14)
A1: Variable Set [ Name:%leave_enabled To:Boot Check,Incoming SMS Check,Stealth Mode Do Maths:Off Append:Off ]
A2: Variable Split [ Name:%leave_enabled Splitter:, Delete Base:Off ]
A3: Variable Set [ Name:%enabled_profiles To:%PENABLED Do Maths:Off Append:Off ]
A4: Variable Split [ Name:%enabled_profiles Splitter:, Delete Base:Off ]
A5: Array Pop [ Variable:%enabled_profiles Position:1 To Var: ]
A6: For [ Variable:%current_profile Items:%enabled_profiles() ]
A7: For [ Variable:%temp Items:%leave_enabled() ]
A8: If [ %current_profile ~ %temp ]
A9: Variable Set [ Name:%skip To:1 Do Maths:Off Append:Off ]
A10: Goto [ Type:End of Loop Number:1 Label: ]
A11: End If
A12: End For
A13: Flash [ Text:%current_profile Long:Off ]
A14: If [ %skip = 1 ]
A15: Variable Set [ Name:%skip To:0 Do Maths:Off Append:Off ]
A16: Goto [ Type:Top of Loop Number:1 Label:outer_loop ]
A17: End If
A18: [X] Profile Status [ Name:%current_profile Set:Off ]
A19: End For


enabled_profiles contains "Currently Charging,BT On for Calls,Speakerphone,Stealth Mode,Apps for Hacker's Keyboard...". The flash action at A13 flashes "Currently Charging", "BT On for Calls", "Speakerphone", "Stealth Mode" in that order (as expected). Then it keeps flashing "Stealth Mode" over and over. If I disable the Goto at A16, the task completes normally but then ALL profiles would be deactivated.

Anyone has any idea where my error is?

Rich D

unread,
Jun 9, 2013, 2:43:02 PM6/9/13
to tas...@googlegroups.com

> Profile: Stealth Mode (13)
> State: Variable Value [ Name:%Theft_Detected Op:Matches Value:1 ]
> Enter: Anon (14)
> A1: Variable Set [ Name:%leave_enabled To:Boot Check,Incoming SMS Check,Stealth Mode Do Maths:Off Append:Off ]
> A2: Variable Split [ Name:%leave_enabled Splitter:, Delete Base:Off ]
> A3: Variable Set [ Name:%enabled_profiles To:%PENABLED Do Maths:Off Append:Off ]
> A4: Variable Split [ Name:%enabled_profiles Splitter:, Delete Base:Off ]
> A5: Array Pop [ Variable:%enabled_profiles Position:1 To Var: ]
> A6: For [ Variable:%current_profile Items:%enabled_profiles() ]
> A7: For [ Variable:%temp Items:%leave_enabled() ]
> A8: If [ %current_profile ~ %temp ]
> A9: Variable Set [ Name:%skip To:1 Do Maths:Off Append:Off ]
> A10: Goto [ Type:End of Loop Number:1 Label: ]
> A11: End If
> A12: End For
> A13: Flash [ Text:%current_profile Long:Off ]
> A14: If [ %skip = 1 ]
> A15: Variable Set [ Name:%skip To:0 Do Maths:Off Append:Off ]
> A16: Goto [ Type:Top of Loop Number:1 Label:outer_loop ]
> A17: End If
> A18: [X] Profile Status [ Name:%current_profile Set:Off ]
> A19: End For
>

I have not used the 'goto "top of loop"' action before so I am not sure why you get the endless loop but i do have a few suggestions to simplify things..

1. The for loop will work fine with just a comma separated list in the variable.  So I think you could just do it with one for loop based on the %PENABLED

A6: For [ Variable:%current_profile Items:%PENABLED ]

and to check for profiles to remain active just do a

Profile status off ;  If %leave_enabled does not match  *,%current_profile,*

You will need to add a comma before the first profile name (Boot Check)  in this variable set action..

> A1: Variable Set [ Name:%leave_enabled To:,Boot Check,Incoming SMS Check,Stealth Mode Do Maths:Off Append:Off ]

Rich...

Rich D

unread,
Jun 9, 2013, 4:22:28 PM6/9/13
to tas...@googlegroups.com

> Profile: Stealth Mode (13)
> State: Variable Value [ Name:%Theft_Detected Op:Matches Value:1 ]
> Enter: Anon (14)
> A1: Variable Set [ Name:%leave_enabled To:Boot Check,Incoming SMS Check,Stealth Mode Do Maths:Off Append:Off ]
> A2: Variable Split [ Name:%leave_enabled Splitter:, Delete Base:Off ]
> A3: Variable Set [ Name:%enabled_profiles To:%PENABLED Do Maths:Off Append:Off ]
> A4: Variable Split [ Name:%enabled_profiles Splitter:, Delete Base:Off ]
> A5: Array Pop [ Variable:%enabled_profiles Position:1 To Var: ]
> A6: For [ Variable:%current_profile Items:%enabled_profiles() ]
> A7: For [ Variable:%temp Items:%leave_enabled() ]
> A8: If [ %current_profile ~ %temp ]
> A9: Variable Set [ Name:%skip To:1 Do Maths:Off Append:Off ]
> A10: Goto [ Type:End of Loop Number:1 Label: ]
> A11: End If
> A12: End For
> A13: Flash [ Text:%current_profile Long:Off ]
> A14: If [ %skip = 1 ]
> A15: Variable Set [ Name:%skip To:0 Do Maths:Off Append:Off ]
> A16: Goto [ Type:Top of Loop Number:1 Label:outer_loop ]
> A17: End If
> A18: [X] Profile Status [ Name:%current_profile Set:Off ]
> A19: End For
>

> Anyone has any idea where my error is?

I think the problem is that the 'goto top of loop' is going to A7 not A6 as you expect.  From the user guide...

Top of Loop: jump to the "first" For action above the current action ('continue')

Rich...

Pent

unread,
Jun 10, 2013, 2:31:59 AM6/10/13
to Tasker

> I think the problem is that the 'goto top of loop' is going to A7 not A6 as
> you expect.  From the user guide...

Possibly there are other problems, but I tested a simple For with a
Goto (Top Of Loop) and
it's definitely not working correctly (it doesn't increment to the
next item in the For as 'continue'
would - since it's described as 'like continue' in the help text, I'm
pretty sure that's unintended).

I can see why it's happening but don't want to fix it till after the
current beta has been released
as stable (otherwise I have to build another beta release because it's
tricky code). Sorry for the delay!

Pent

Ivelin Ivanov

unread,
Jun 10, 2013, 2:54:52 AM6/10/13
to tas...@googlegroups.com
On Sunday, June 9, 2013 8:43:02 PM UTC+2, Rich D wrote:

I have not used the 'goto "top of loop"' action before so I am not sure why you get the endless loop but i do have a few suggestions to simplify things..

1. The for loop will work fine with just a comma separated list in the variable.  So I think you could just do it with one for loop based on the %PENABLED

A6: For [ Variable:%current_profile Items:%PENABLED ]

and to check for profiles to remain active just do a

Profile status off ;  If %leave_enabled does not match  *,%current_profile,*

You will need to add a comma before the first profile name (Boot Check)  in this variable set action..

> A1: Variable Set [ Name:%leave_enabled To:,Boot Check,Incoming SMS Check,Stealth Mode Do Maths:Off Append:Off ]

Rich...


Thanks Rich, I hadn't thought of using matching (or rather, that "LONG_TEXT" ~ "*PART_OF_LONG_TEXT*" would return true, which is of course rather obvious so I'm just dumb, hehe). I couldn't get it to work exactly as you described, because it seems that the For action takes %PENABLED as a single entry in its comma-separated list of items to loop through, instead of looking inside it and separating each profile. I suppose that's actually logical because this way you can actually have commas in the text of some iterations. Like for example, For [ Variable:%xxx Items:%PENABLED,apple,banana ] would run three times, once for ",Profile1,Profile2,...,Profile(n)", once for "apple" and once for "banana". So I still have to do a split on %PENABLED before putting it in the For action. Long story short, this is my current (and flawlessly working) code:


A1: Variable Set [ Name:%leave_enabled To:Boot Check,Incoming SMS Check,Stealth Mode Do Maths:Off Append:Off ]
A2: Variable Set [ Name:%enabled_profiles To:%PENABLED Do Maths:Off Append:Off ]
A3: Variable Split [ Name:%enabled_profiles Splitter:, Delete Base:Off ]
A4: Array Pop [ Variable:%enabled_profiles Position:1 To Var: ]
A5: For [ Variable:%current_profile Items:%enabled_profiles() ]
A6: If [ %leave_enabled !~ *%current_profile* ]
A7: Profile Status [ Name:%current_profile Set:Off ]
A8: Variable Set [ Name:%disabled_profiles To:,%current_profile Do Maths:Off Append:On ]
A9: End If
A10: End For
A11: Write File [ File:Tasker/disabled_profiles.txt Text:%disabled_profiles Append:Off Add Newline:On ] If [ %disabled_profiles Is Set ]

Thanks again for the help :)



On Monday, June 10, 2013 8:31:59 AM UTC+2, Pent wrote:

Possibly there are other problems, but I tested a simple For with a
Goto (Top Of Loop) and
it's definitely not working correctly (it doesn't increment to the
next item in the For as 'continue'
would - since it's described as 'like continue' in the help text, I'm
pretty sure that's unintended).

I can see why it's happening but don't want to fix it till after the
current beta has been released
as stable (otherwise I have to build another beta release because it's
tricky code). Sorry for the delay!

Pent

Hey Pent, thanks for replying. No problem about delaying the fix, I got my task to work without any Gotos so it's no rush :). Gotos probably aren't used for loop control that much anyway, otherwise someone else would have noticed that bug before me.

Rich D

unread,
Jun 10, 2013, 6:28:10 AM6/10/13
to tas...@googlegroups.com

I couldn't get it to work exactly as you described, because it seems that the For action takes %PENABLED as a single entry in its comma-separated list of items to loop through, instead of looking inside it and separating each profile. I suppose that's actually logical because this way you can actually have commas in the text of some iterations. Like for example, For [ Variable:%xxx Items:%PENABLED,apple,banana ] would run three times, once for ",Profile1,Profile2,...,Profile(n)", once for "apple" and once for "banana". So I still have to do a split on %PENABLED before putting it in the For action.

Sorry for any time you might have lost because of my incorrect information, I thought I had use a variable like that in a for loop but I must have been thinking of something else..  :(

You are of course correct in that a variable containing a comma separated list will not produce separate iterations in a for loop. Just to be clear for others a loop like this:

Forloop (78)
A1: Variable Set [ Name:%abc To:a,b,c,d,e,f Do Maths:Off Append:Off ]
A2: For [ Variable:%items Items:%abc ]
A3: Flash [ Text:%items Long:Off ]
A4: End For

Will result in one flash containing "a,b,c,d,e,f"

>
>
> A1: Variable Set [ Name:%leave_enabled To:Boot Check,Incoming SMS Check,Stealth Mode Do Maths:Off Append:Off ]
> A2: Variable Set [ Name:%enabled_profiles To:%PENABLED Do Maths:Off Append:Off ]
> A3: Variable Split [ Name:%enabled_profiles Splitter:, Delete Base:Off ]
> A4: Array Pop [ Variable:%enabled_profiles Position:1 To Var: ]
> A5: For [ Variable:%current_profile Items:%enabled_profiles() ]
> A6: If [ %leave_enabled !~ *%current_profile* ]
> A7: Profile Status [ Name:%current_profile Set:Off ]
> A8: Variable Set [ Name:%disabled_profiles To:,%current_profile Do Maths:Off Append:On ]
> A9: End If
> A10: End For
> A11: Write File [ File:Tasker/disabled_profiles.txt Text:%disabled_profiles Append:Off Add Newline:On ] If [ %disabled_profiles Is Set ]
>

The only problem I see with it now is I believe it will fail if you have two separate  profile names such as "Power" and "Power Off". If you put "Power" in %leave_enabled it will leave both "Power" And "Power Off" enabled. 

Using *,%current_profile,* As the search criteria Will prevent this, You just need to make sure that %leave_enabled has a comma in the beginning and the end of it. 

Rich..

Ivelin Ivanov

unread,
Jun 10, 2013, 8:20:50 AM6/10/13
to tas...@googlegroups.com
On Monday, June 10, 2013 12:28:10 PM UTC+2, Rich D wrote:

The only problem I see with it now is I believe it will fail if you have two separate  profile names such as "Power" and "Power Off". If you put "Power" in %leave_enabled it will leave both "Power" And "Power Off" enabled. 

Using *,%current_profile,* As the search criteria Will prevent this, You just need to make sure that %leave_enabled has a comma in the beginning and the end of it. 

Rich..


Ah, you are right of course, I completely forgot about that. As for any "lost time" - I don't see it that way, but instead as helping me learn yet another thing I didn't know before. As long as it gets me in the right direction (which all of your suggestions more than amply did), I don't mind at all if I have to tweak something or other to get it to work according to my expectations :)
Reply all
Reply to author
Forward
0 new messages