There are tricks to using Tasker variables in Watchmaker. I learnt this the hard way and after much relearning Lua. Thankfully, Lua is not too difficult a language to get into. If you have done any BASIC or shell scripting, you won't be too lost!
Tasker variables that are sent to Watchmaker are prefixed with a t and enclosed around { }. All variable names are converted to lowercase, so bare this in mind when running Tasks. For example, %SomeVar will be {tsomevar}. This can result in issues if you use a global and local identical, for example %loc and %LOC - both will be {tloc} to Watcmaker.
In most cases, Tasker variables are seen as Lua tables to Watchmaker. This can make using the raw {tvariable} difficult to use in formula or string conversions. So we ideally want to map them to var_variables in the Main Script.
The raw {tvariables} will update as you send them through Watchmaker (when screen is bright). This is fine for simple sending of small data sets where no math or string formulas are used. However, to make everything pretty and error free, there are tricks to make them more efficient and usable.
This includes being updated on_display_bright() as well as results from ontap actions.
In this example, we'll send %taskerstring containing a text string Hello World and %taskernumber containing a number 62.21
There is a trick to handling both!
function static_variables()
taskerstring=wm_tag('{ttaskerstring}')
var_string=tostring(taskerstring)
taskernumber=wm_tag('{ttaskernumber}')
var_number=tonumber(taskernumber)
end
static_variables()
Now, this alone won't do anything but initialize the var_ variables to use in faces. What it does, it initializes the variable as Lua only local variable. The next step then sets it to a type, string or number. This is important to know what we are sending to map correctly. If your variable contains both strings and numbers, whether together or alone, use tostring().
We can error check against them easily!
var_string == nil and 'No string yet' or var_string
and
var_number == nil and '-1' or var_number
WikiD Instuctables is a not-for-profit venture by CommWi Projects. CommWi Projects or any person affiliated with, are not in any official way, affiliated, endorsed, sponsored or licensed by any of the software, hardware, companies or persons documented on this site. Please address any Copyright or IP concerns to myself so they may be dealt with appropriately. Content hosted on this site, unless otherwise stated, is provided under the license Attribution-ShareAlike 4.0 International (CC BY-SA 4.0).