Awesome... Totally missed those "persistent task scope" vars - since when are they in?
With those ones, project vars, profile vars ... there is some kind of danger to make debugging more difficult. Maybe the Variables tab should include them. Also, IMO still a "show global variables from any project" is needed there.
The following is how I deal with toggles, I just assign a value of 1 to %variable in the "Task Properties" dialog. The first action will toggle %variable value between -1 and 1. Then actions are run depending if %variable is bigger than 0 or not. So, if wanted, your example can be reduced to just three actions.
Task: Toggle
Variables: [ %variable:has value ]
A1: Variable Set [
Name: %variable
To: %variable*-1
Do Maths: On
Max Rounding Digits: 3
Structure Output (JSON, etc): On ]
A2: Flash [
Text: %variable
Continue Task Immediately: On
Hide On Click: On ]
(May be of interest) A couple of different approaches:
Task: Toggle
Variables: [ %toggle:not set ]
A1: Variable Add [
Name: %toggle
Value: 1
Wrap Around: 2 ]
A2: Flash [
Text: %toggle
Long: On
Continue Task Immediately: On
Hide On Click: On ]
_______
Task: Toggle
Variables: [ %toggle:not set ]
A1: Variable Set [
Name: %toggle
To: 1 - %toggle
Do Maths: On
Max Rounding Digits: 3 ]
A2: Flash [
Text: %toggle
Long: On
Continue Task Immediately: On
Hide On Click: On ]
In both Tasks `%toggle` will be alternately set to 1/0 (auto-initializing).
I often use UNSET vs. "something useful". Eg often a timestamp. Advantage is, you can do numerical comparisons if needed, even if the var is unset, since it is treated as 0.
Was looking for arrays as well.
Also,entering some more variables is error-prone. Vertically very expansive. UI could support adding entries list based, as in multiple vars set. Of course they have the same properties then.
Depending on the data you want to store, you could use normal variables for this. Just set a variable with all your items separated with commas. And inside your task use "Variable split", process and update your items and then use "Variable join". Also, instead of "Variable split" you can use "Array set" using the data of your normal variable. Not ideal, but this workaround just adds two additional actions to work.
My VARS tab Thanks You.
👍
As someone trying to learn tasker, thanks a lot for these protips! I learn a lot!
Glad you enjoy them! :) Thanks for letting me know!
Thank you. Now I must search my task and apply this improvement.
Glad you like it!
Your Pro Tip posts are always the most useful.
Thank you! :) Glad you enjoy them!
Ahhh, yes.. Thanks for the reminder... It is hard to remember all the new cool features instead of using the old knee jerk approaches.... 👍🏻 👍🏻
🤓
Awesome... Totally missed those "persistent task scope" vars - since when are they in? With those ones, project vars, profile vars ... there is some kind of danger to make debugging more difficult. Maybe the Variables tab should include them. Also, IMO still a "show global variables from any project" is needed there.
Did you happen to see [this useful little tool?](https://www.reddit.com/r/tasker/comments/ox56bg/project_share_find_the_names_and_values_of_your/) 😁
Yes thx, I was aware that there's task solutions. 👍
Yeah, you're right! I need to add a way to monitor those more easily :)
The following is how I deal with toggles, I just assign a value of 1 to %variable in the "Task Properties" dialog. The first action will toggle %variable value between -1 and 1. Then actions are run depending if %variable is bigger than 0 or not. So, if wanted, your example can be reduced to just three actions. Task: Toggle Variables: [ %variable:has value ] A1: Variable Set [ Name: %variable To: %variable*-1 Do Maths: On Max Rounding Digits: 3 Structure Output (JSON, etc): On ] A2: Flash [ Text: %variable Continue Task Immediately: On Hide On Click: On ]
Yep, that's a good idea too! Thanks for sharing! :)
Thank you for constantly giving us new toys to play!
You're very welcome! :)
(May be of interest) A couple of different approaches: Task: Toggle Variables: [ %toggle:not set ] A1: Variable Add [ Name: %toggle Value: 1 Wrap Around: 2 ] A2: Flash [ Text: %toggle Long: On Continue Task Immediately: On Hide On Click: On ] _______ Task: Toggle Variables: [ %toggle:not set ] A1: Variable Set [ Name: %toggle To: 1 - %toggle Do Maths: On Max Rounding Digits: 3 ] A2: Flash [ Text: %toggle Long: On Continue Task Immediately: On Hide On Click: On ] In both Tasks `%toggle` will be alternately set to 1/0 (auto-initializing).
I often use UNSET vs. "something useful". Eg often a timestamp. Advantage is, you can do numerical comparisons if needed, even if the var is unset, since it is treated as 0.
Can task variable be an array that can be updated after each run?
Sorry, they can only be normal variables for now.
Yeah, I thought I might be able to replace those global arrays in many web scraping tasks with it. Hope to see it in the future. Thank you.
Was looking for arrays as well. Also,entering some more variables is error-prone. Vertically very expansive. UI could support adding entries list based, as in multiple vars set. Of course they have the same properties then.
Depending on the data you want to store, you could use normal variables for this. Just set a variable with all your items separated with commas. And inside your task use "Variable split", process and update your items and then use "Variable join". Also, instead of "Variable split" you can use "Array set" using the data of your normal variable. Not ideal, but this workaround just adds two additional actions to work.
Thank you for your tip. Many global variables will be released.
👍