Array with index as a variable in a loop

62 views
Skip to first unread message

francwalter

unread,
Dec 8, 2023, 5:21:58 AM12/8/23
to Tasker
Hallo
I want to iterate in a Loop Action through an array, but I noticed, that this does not work:

Task: TestArrayInForLoop
   
    A1: Variable Set [
         Name: %word
         To: this,does,not,work
         Structure Output (JSON, etc): On ]
   
    A2: Variable Split [
         Name: %word
         Splitter: , ]
   
    A3: Variable Set [
         Name: %joker_hits
         To: 4
         Structure Output (JSON, etc): On ]
   
    A4: For [
         Variable: %joker_hit
         Items: 1:%joker_hits
         Structure Output (JSON, etc): On ]
   
        A5: Flash [
             Text: joker_hits: %joker_hits
             joker_hit: %joker_hit
             
             word%joker_hit: %word%joker_hit
             
             word1: %word1
             word2: %word2
             word3: %word3
             word4: %word4
             Tasker Layout: On
             Title: joker_hits
             Timeout: 120000
             Dismiss On Click: On ]
   
    A6: End For

The variable %word%joker_hit is not like %word1, %word2, %word3 and %word4 in the loop, but just the number %joker_hit added as number and not as the array index.
I get in the Flash Action as %word%joker_hit always the full array parts.
This I get in the 4 loops (each loop a line):

this,does,not,work1
this,does,not,work2
this,does,not,work3
this,does,not,work4

But not:

this
does
not
work

Maybe I dont find it in the help how to do this, or maybe I forgot it, or maybe this is just not possible this way?
How can I iterate the array with %joker_hit as index?
Thanks
frank
Tasker 6.2.22 on Android 9

francwalter

unread,
Dec 8, 2023, 5:23:56 AM12/8/23
to Tasker
So silly I am and forgetty.
It is just as simple as using paranthesis with the index:

word%joker_hit: %word(%joker_hit)

I remembered again :)
Reply all
Reply to author
Forward
0 new messages