Page 1 of 1

need help regarding concat function

Posted: 17 Aug 2017 09:03
by houdinix64
Hi guys I need your help please.

my script:

smartStates = newList("Smart Rotate","Smart Timeout","Smart Notification");

for (smartState in smartStates)

if( contains(smartState,'Rotate' )==true )
detail = "on"

if( contains(smartState,'Timeout' )==true )
detail = "1 minute"

if( contains(smartState,'Notification' )==true )
detail = "active"

smartDetails = concat(smartState, ' (', detail, ')');


// string result be in this kind of format

Smart Rotate (on)
Smart Timeout (1minute)
Smart Notification (active)


Re: need help regarding concat function

Posted: 17 Aug 2017 10:37
by Desmanto
I am confused what you want to do. If "Smart Rotate" always have the value (on), then why don't just put the value "Smart Rotate (on)" directly? Same for other value.
You can combine them later, using join() and newline
text = join(smartStates, "\n")
Then display it (such as in notification on screen) as {text}

When using loop, it is better to use new variable which is completely different to avoid confusion. I am confused until I realize there is no 's' in the for. Better use
for ( i in smarStates)
Then use i in the loop, save your code, save your typing and avoid confusion.

contains() will always result in true or false, so no need additional "== true" in if()
Since the value comes in pair, maybe you should use map() instead. There is action map values you can use, or map function as well.

Re: need help regarding concat function

Posted: 18 Aug 2017 06:25
by houdinix64
Thanks Desmanto for your help and tips in creating scripts. Your idea perfectly work on my flow. Thanks again