Array with newlines?

87 views
Skip to first unread message

Megan Taylor

unread,
Sep 10, 2014, 11:13:02 AM9/10/14
to tas...@googlegroups.com
I have a var TLIST() which prints out (for example) banana,pineapple,strawberry,melon. I want to get
 
banana
pineapple
strawberry
melon

Is this possible, and how would I go about that?




Scott

unread,
Sep 10, 2014, 12:15:37 PM9/10/14
to tas...@googlegroups.com
Just do a Variable Split with a comma as the splitter.  That will give you an array with those four elements.  Then you can "print off" the elements however you want.

The UI has changed since this article was written and there are some new features it doesn't mention but it's a good place to start with using arrays in Tasker.

http://www.pocketables.com/2012/10/beginners-guide-to-tasker-part-7-variable-arrays.html
Message has been deleted

Megan Taylor

unread,
Sep 10, 2014, 1:49:06 PM9/10/14
to tas...@googlegroups.com
I've read that article, and still find the way that Tasker does arrays confusing. Isn't TLIST() already an array?

Scott

unread,
Sep 10, 2014, 1:59:06 PM9/10/14
to tas...@googlegroups.com
TLIST() isn't Tasker notation, so it's hard to say.  "Prints out" is also ambiguous.  There's no "print" action in Tasker.  

If your data is already in an array, just "print out" your data one element at a time with a  new line between each element.

Perhaps you should just export the applicable task(s) as descriptions (not XML) and post it/them here.

Megan Taylor

unread,
Sep 10, 2014, 2:06:02 PM9/10/14
to tas...@googlegroups.com
If you scroll down to variable arrays on this page, it shows the array notation I'm using: http://tasker.dinglisch.net/userguide/en/variables.html

I'm passing a single variable to Dashclock from Tasker.

This is my javascript:

jsonData = JSON.parse(global("HTTPD"));

var y = 0; // needed a separate incrementing var for TLIST

if (jsonData[0].data[0] !== 'undefined') {
    for (i = 0; i < jsonData[0].data.length; i++) {
        setGlobal('TLIST'+y, jsonData[0].data[i].content);
        y++;
    }
}

if (jsonData[1].data[0] !== 'undefined') {
    for (i = 0; i < jsonData[1].data.length; i++) {
        setGlobal('TLIST'+y, jsonData[1].data[i].content);
        y++;
    }
}

if (jsonData[2].data[0] !== 'undefined') {
    for (i = 0; i < jsonData[2].data.length; i++) {
        setGlobal('TLIST'+y, jsonData[2].data[i].content);
        y++;
    }
}

Scott

unread,
Sep 10, 2014, 3:23:44 PM9/10/14
to tas...@googlegroups.com
Well, all Tasker variables start with a % and all caps is reserved for all built in variables, but I think I understand what you're asking better.  ;)

When you have an array in Tasker and reference it by adding the parenthesis (i.e. %tlist()) what you get is the contents of the array separated by commas.  It's just a convenient, built in way to get all of the contents of an array.  If you want something other than that you have to reference it differently.  You'll likely need a for loop that does something with each element individually if you want something different.   

Megan Taylor

unread,
Sep 10, 2014, 4:11:39 PM9/10/14
to tas...@googlegroups.com
Got it! Wow, that's so complicated. Thanks for pointing me in the right direction.
--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/IsXykPFt75I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/d/optout.

Scott Miller

unread,
Sep 10, 2014, 4:28:49 PM9/10/14
to tas...@googlegroups.com


On Sep 10, 2014 3:24 PM, "Scott" <scott...@gmail.com> wrote:
>
> ... all caps is reserved for all built in variables ...

This is not accurate. Built in variables happen to be all caps, because they are global variables, but any global variable, even user defined variables, can be all caps. See the user guide for details about global and local variables.

Reply all
Reply to author
Forward
0 new messages