Creating text files & Displaying variables

931 views
Skip to first unread message

Knowthenazz (Moto Milestone, Cyanogen)

unread,
May 10, 2011, 3:18:23 AM5/10/11
to Tasker

Hi,

I'm pretty new to Tasker, and was wondering if someone would be able
to help me with some basic questions.

I've been using Write to File to output a debug log to a text file,
but, how do you create the file if it doesn't already exist?

Also, when I attempt to display the contents of numeric variables,
Write to File doesn't translate the values. For example, the output
of my text file is as follows:

Home = %Home
Sleeping = %Sleeping




I'm expecting:

Home = 1
Sleeping = 0



What am I doing wrong?

Thanks in advance!



Pent

unread,
May 10, 2011, 4:41:21 AM5/10/11
to Tasker
> I've been using Write to File to output a debug log to a text file,
> but, how do you create the file if it doesn't already exist?

It will be created if it doesn't exist.

> Also, when I attempt to display the contents of numeric variables,
> Write to File doesn't translate the values.  For example, the output
> of my text file is as follows:
>
> Home = %Home
> Sleeping = %Sleeping
>
> I'm expecting:
>
> Home = 1
> Sleeping = 0
>
> What am I doing wrong?

If the variables come out without being replaced, it means there is no
value defined for them. Note that the names are case-sensitive, maybe
you used e.g. %HOME before ?

Pent

Knowthenazz (Moto Milestone, Cyanogen)

unread,
May 10, 2011, 5:37:50 AM5/10/11
to Tasker
Hi Pent,

Thanks for replying to my questions.

The variables %Home and %Sleep were previously defined in other
tasks. I read in another forum that variables in Tasker were
persistent (since the last Tasker startup) and global for all tasks.
Is that not true?

If not, is there a way to pass variables to tasks?

Thanks!

Pent

unread,
May 10, 2011, 8:30:07 AM5/10/11
to Tasker
> The variables %Home and %Sleep were previously defined in other
> tasks.

And are you sure those tasks actually ran ? And the names had the same
case ? Have you got any conditions on the Variable Set actions ?
Perhaps you've done Variable Clear at some point ?

Try this: Menu / More / Run An Action / Variables / Variable Set %Home
1

Then your write file again.

>  I read in another forum that variables in Tasker were
> persistent  (since the last Tasker startup) and global for all tasks.
> Is that not true?

More so, they're persistent since the last full uninstall and
reinstall.
Also global, yes.

Pent

Knowthenazz (Moto Milestone, Cyanogen)

unread,
May 10, 2011, 2:18:40 PM5/10/11
to Tasker
Hi Pent,

Thanks for the insight.

Yes, you were right, at some points during my tests the variables were
in a cleared state, and sometimes not. I guess what was confusing me
was that I didn't expect the variable to be undefined if it was
cleared. I was expecting 0, or NULL.

Is it by design that the variable is undefined if cleared?

I ran a couple of more tests, and if I force one of the two variables
as set to "1", it seems to work.

Home = %Home
Sleeping = 1


But, if both the variables are set, I get the exact same result. I
would have expected:

Home = 1
Sleeping = 1


Is this a formatting issue? Or if I'm using the set value of 1, do I
need to have the "do math" option enabled (although I wouldn't think
it'd matter if I'm treating the variable as a boolean).

Thanks for helping me out Pent!

Knowthenazz (Moto Milestone, Cyanogen)

unread,
May 10, 2011, 2:31:22 PM5/10/11
to Tasker
Hi Pent,

On thinking about this matter more, it does make sense to me now that
if a variable is cleared, it should be undefined. I guess it's just
terminology hump for me. My bad :)

With regard to writing out the variables, that even though they aren't
being translated properly when writing to a text file, they do seem to
behave properly when used in conditionals in the current task.

I'll do a bit more experimentation and see if I can isolate this a bit
more.

Thanks!


On May 10, 11:18 am, "Knowthenazz (Moto Milestone, Cyanogen)"

Pent

unread,
May 10, 2011, 2:35:33 PM5/10/11
to Tasker
> Is it by design that the variable is undefined if cleared?

Yes, to help prevent accidental replacement of text that the user
didn't intend to be a variable name,

If you want 0 you can set it to 0.

> I ran a couple of more tests, and if I force one of the two variables
> as set to "1", it seems to work.
>
> Home = %Home
> Sleeping = 1
>
> But, if both the variables are set, I get the exact same result.  I
> would have expected:
>
> Home = 1
> Sleeping = 1
>
> Is this a formatting issue?

I'm going to vote for user-error again :-)

Try inserting a new action before the Write File:

Variable Set, %Home, 1

To make sure there's actually something in %Home.

> Or if I'm using the set value of 1, do I
> need to have the "do math" option enabled (although I wouldn't think
> it'd matter if I'm treating the variable as a boolean).

Doesn't matter, do maths is for if you have 3 + 2 / 0.4 or whatever.

Pent

Knowthenazz (Moto Milestone, Cyanogen)

unread,
May 10, 2011, 3:27:14 PM5/10/11
to Tasker

I'm voting for user error as well :)

I'll play around with it some more and report back.

Thanks again Pent! Your responsiveness and helpfulness is truly
impressive.

Knowthenazz (Moto Milestone, Cyanogen)

unread,
May 23, 2011, 7:04:23 AM5/23/11
to Tasker
UPDATE:

Hi,

I just wanted to report back.

I wasn't able to get the user variable to display consistently when I
was using the Set to 1/Clear method.

But when I switched to the Set to 1/Set to 0 method (that Pent)
suggested, it works perfectly now.

Thanks for your help!



On May 10, 12:27 pm, "Knowthenazz (Moto Milestone, Cyanogen)"
Reply all
Reply to author
Forward
0 new messages