Javascriptlet won't change Tasker variable.

340 views
Skip to first unread message

R.M. Levitt

unread,
Sep 7, 2018, 6:09:23 AM9/7/18
to Tasker
The play button on the Javascriptlet gives an “OK" toast and I'm not seeing any errors, but the scriptlet simply will not change the value of a variable I have defined in Tasker no matter what I do. This is what I have:

A1: Variable Set
Name %testVar To foo
A2: Javascriptlet
var testVar = "bar";
flash(testVar);
A3: Popup Text %testVar

The Javascript flash says "bar" but the Tasker popup (A3) still says "foo" as if my scriptlet did nothing. The scriptlet Auto Exit is set to true and the Timeout is set to 45 seconds. I've also tried this Javascript:

var a = global('testVar');
a = "bar";
flash(a);
tk.setLocal('testVar', a);

Again, the Javascript flash says "bar" but the Tasker Popup (A3) still reports %testVar as "foo". Even these two attempts did nothing:

1) var testVar = "bar";

2) tk.setLocal('testVar', "bar");

In every one of these cases, the Tasker variable %testVar is still "foo" in the Popup (A3) just after the scriptlet, the same value I initially set for it in A1 just PRIOR to the scriptlet (A2). What in the world could I possibly be doing wrong? Why won't the Javascript change the value of %testVar??

Robert Ryan

unread,
Sep 7, 2018, 6:52:49 AM9/7/18
to tas...@googlegroups.com
You need to use setGlobal() to change the value of global variables. This works:

        Test
        
    A1: Variable Set 
        Name: %testVar 
        To: foo 
        Recurse Variables: Off 
        Do Maths: Off 
        Append: Off 
        
    A2: JavaScriptlet 
        Code: setGlobal( 'testVar', 'bar' ) 
        Auto Exit: On 
        Timeout (Seconds): 45 
        
    A3: Flash 
        Text: %testVar 
        Long: Off 

-- 
You received this message because you are subscribed to the Google Groups "Tasker" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tasker+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

R.M. Levitt

unread,
Sep 7, 2018, 9:28:11 AM9/7/18
to Tasker
Thank you, I got it ironed out now.
Reply all
Reply to author
Forward
0 new messages