Hi, I wrote an article about basic usage of Watchmaker for czech users. Now I wrote second part about scripts and I believe it could be interresting for more people so I'd try to translate it also to english.
This article expects knowledge about creating watchfaces in Watchmaker and basic programming skills.
Go to the application Watchmaker, select a watchface, then choose Customize Watch. Scroll down, there is a field Script. The scripts are writen in Lua language.
You can call the scripts as an Tap Action or you can call a function instead of hardcoded text. Huge scripts is better to write in Scipt field and use it where you need.
Show a date
For an easy example, we want to have a watchface which displays only date like "Fr, 22. 2." We can use direct elements like {ddw2}, {dd}. {dn}.
Or we can call a function var_getDate(). It's definition is on 3rd picture bellow:
function var_getDate() return {ddw2} .. ', ' .. {dd} .. '. ' .. {dn} .. '.' end
A function is a block of a code which is able to return an result. In this case we have combined the texts.
You can see that the elements have different behavior in direct text input and in a script. In a text input it is possible to combine fields easy together but in a script you have to use a command: ..
Text is bounded by character '
OK, for displaying a date is using a script an overkill. But what if we want to display day in week uppercase but only for Fridays?
As you can see I added only one easy condition to the code...
function var_getDate() day = {ddw2} if {ddw0} == 5 then day = string.upper(day) end return day .. ', ' .. {dd} .. '. ' .. {dn} .. '.' end
Special characters
In some cases you need to display special characters like names or places, e.g. in a calendar event.
I created an example with a czech word "Náměstí" (a square). I believe that you feel the text as weird, so we can convert special characters to ASCII. I have prepared also an function to return first or second calendar event which automaticcaly calls converting to ASCII. If you need additional special characters just add them as a new lines.
function var_getEvent(n) eventBegin = {{c1b}, {c2b}} eventText = {{c1t}, {c2t}} text = eventBegin[n] .. ' - ' .. eventText[n] return var_ToASCII(text) end function var_ToASCII(strText) a=strText a=string.gsub(a, "á", "a") a=string.gsub(a, "č", "c") a=string.gsub(a, "ď", "d") a=string.gsub(a, "é", "e") a=string.gsub(a, "ě", "e") a=string.gsub(a, "í", "i") a=string.gsub(a, "ň", "n") a=string.gsub(a, "ó", "o") a=string.gsub(a, "ř", "r") a=string.gsub(a, "š", "s") a=string.gsub(a, "ť", "t") a=string.gsub(a, "ú", "u") a=string.gsub(a, "ů", "u") a=string.gsub(a, "ý", "y") a=string.gsub(a, "ž", "z") a=string.gsub(a, "Á", "A") a=string.gsub(a, "Č", "C") a=string.gsub(a, "Ď", "D") a=string.gsub(a, "É", "E") a=string.gsub(a, "Ě", "E") a=string.gsub(a, "Í", "I") a=string.gsub(a, "Ň", "N") a=string.gsub(a, "Ó", "O") a=string.gsub(a, "Ř", "R") a=string.gsub(a, "Š", "S") a=string.gsub(a, "Ť", "T") a=string.gsub(a, "Ú", "U") a=string.gsub(a, "Ů", "U") a=string.gsub(a, "Ý", "Y") a=string.gsub(a, "Ž", "Z") return a end
Display holidays
In Czech republic has each day assigned a name and people celebrating they nameday. I'm not sure if something like that is in UK but it is a good example how to work with arrays. You can put there instead of czech names what you want 🙂
function var_get_svatek() md={31,28,31,30,31,30,31,31,30,31,30,31} m1 = {"Nový rok","Karina","Radmila","Diana","Dalimil","Tři Králové","Vilma","Čestmír","Vladan","Břetislav","Bohdana","Pravoslav","Edita","Radovan","Alice","Ctirad","Drahoslav","Vladislav","Doubravka","Ilona","Běla","Slavomír","Zdeněk","Milena","Miloš","Zora","Ingrid","Otýlie","Zdislava","Robin","Marika",} m2 = {"Hynek","Nela","Blažej","Jarmila","Dobromila","Vanda","Veronika","Milada","Apolena","Mojmír","Božena","Slavěna","Věnceslav","Valentýn","Jiřina","Ljuba","Miloslava","Gizela","Patrik","Oldřich","Lenka","Petr","Svatopluk","Matěj","Liliana","Dorota","Alexandr","Lumír","Horymír"} m3 = {"Bedřich","Anežka","Kamil","Stela","Kazimír","Miroslav","Tomáš","Gabriela","Františka","Viktorie","Anděla","Řehoř","Růžena","Rút","Ida","Elena","Vlastimil","Eduard","Josef","Světlana","Radek","Leona","Ivona","Gabriel","Marián","Emanuel","Dita","Soňa","Taťána","Arnošt","Kvido",} m4 = {"Hugo","Erika","Richard","Ivana","Miroslava","Vendula","Heřman / Hermína","Ema","Dušan","Darja","Izabela","Julius","Aleš","Vincenc","Anastázie","Irena","Rudolf","Valérie","Rostislav","Marcela","Alexandra","Evženie","Vojtěch","Jiří","Marek","Oto","Jaroslav","Vlastislav","Robert","Blahoslav",} m5 = {"1. máj","Zikmund","Alexej","Květoslav","Klaudie","Radoslav","Stanislav","Osvobození od fašismu","Ctibor","Blažena","Svatava","Pankrác","Servác","Bonifác","Žofie","Přemysl","Aneta","Nataša","Ivo","Zbyšek","Monika","Emil","Vladimír","Jana","Viola","Filip","Valdemar","Vilém","Maxim","Ferdinand","Kamila",} m6 = {"Laura","Jarmil","Tamara","Dalibor","Dobroslav","Norbert","Iveta","Medard","Stanislava","Gita","Bruno","Antonie","Antonín","Roland","Vít","Zbyněk","Adolf","Milan","Leoš","Květa","Alois","Pavla","Zdeňka","Jan","Ivan","Adriana","Ladislav","Lubomír","Petr a Pavel","Šárka",} m7 = {"Jaroslava","Patricie","Radomír","Prokop","Cyrila a Metoděje","mistr Jan Hus","Bohuslava","Nora","Drahoslava","Libuše","Olga","Bořek","Markéta","Karolína","Jindřich","Luboš","Martina","Drahomíra","Čeněk","Ilja","Vítězslav","Magdaléna","Libor","Kristýna","Jakub","Anna","Věroslav","Viktor","Marta","Bořivoj","Ignác",} m8 = {"Oskar","Gustav","Miluše","Dominik","Kristián","Oldřiška","Lada","Soběslav","Roman","Vavřinec","Zuzana","Klára","Alena","Alan","Hana","Jáchym","Petra","Helena","Ludvík","Bernard","Johana","Bohuslav","Sandra","Bartoloměj","Radim","Luděk","Otakar","Augustýn","Evelína","Vladěna","Pavlína",} m9 = {"Linda / Samuel","Adéle","Bronislav","Jindřiška","Boris","Boleslav","Regina","Mariana","Daniela","Irma","Denisa","Marie","Lubor","Radka","Jolana","Ludmila","Naděžda","Kryštof","Zita","Oleg","Matouš","Darina","Berta","Jaromír","Zlata","Andrea","Jonáš","Václav","Michal","Jeroným",} m10 = {"Igor","Olívei / Galina","Bohumil","František","Eliška","Hanuš","Justýna","Věra","Štefan / Sára","Marina","Andrej","Marcel","Renáta","Agáta","Tereza","Havel","Hedvika","Lukáš","Michaela","Vendelín","Brigita","Sabina","Teodor","Nina","Beata","Erik","Šarlota / Zoe","Den vzniku československého státu","Silvie","Tadeáš","Štěpánka",} m11 = {"Fenix","Památka zesnulých","Hubert","Karel","Miriam","Liběna","Saskie","Bohumír","Bohdan","Evžen","Martin","Benedikt","Tibor","Sáva","Leopold","Otmar","Den boje studentů za svobodu","Romana","Alžběta","Nikola","Albert","Cecílie","Klement","Emílie","Kateřina","Artur","Xenie","René","Zina","Ondřej",} m12 = {"Iva","Blanka","Svatoslav","Barbora","Jitka","Mikuláš","Ambrož","Květoslava","Vratislav","Julie","Dana","Simona","Lucie","Lýdie","Radana","Albína","Daniel","Miloslav","Ester","Dagmar","Natálie","Šimon","Vlasta","Adam a Eva","1.svátek vánoční","2.svátek vánoční / Štěpán","Žaneta","Bohumila","Judita","David","Silvestr",} svatky = {m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11,m12} m={dn} d={dd} month = svatky[m] day = month[d] return string.sub(day, 1, 15) end
You can see that today are celebrating people which name is Petr.
The function returns only first 15 characters of the text because we don't want to read novels on our watches, do we?
Hiding an element temporary
We could want to hide an element for a few seconds. For example watchhands.
At first we need an hidden element which calls a function which hides watchhands when we tap to it. It will be a circle with Opacity 0 and Tap Action a script which calls our function. Opacity 0 means that the circle is invissible but it reacts on tapping. Opacity -1 means that the circle is invissible and doesn't react to tapping.
I created a property var_s_time which is initialized to 0. It contains time until unhide the watchhands.
Next is there a function var_hideHands() which sets var_s_time to 3 (seconds).
There is also a function on_second(dt) which is called each second when the screen is on. There can be also a function on_milisecond(dt) which is called each milisecond.
There is a limitation for this functions. They can access all variables but the can modify only variables which names start with var_s_ (on_second) or var_ms_ (on_milisecond)
var_s_time = 0
function var_hideHands() var_s_time = 3 end function on_second(dt) if var_s_time > 0 then var_s_time = var_s_time - 1 end end
You can download the watchface from this link: https://www.fotolibb.com/temp/script-demo.zip
12-04-2020 10:51 AM in
WearablesI want to change my layer that shows 1-12 to another layer that shows 13-23, i have done this using a tap button but i want to automate it to change 1-12 to 13-23 dial at 13:00 hrs and back to 1-12 dial at 00:00 hrs.
12-04-2020 11:00 AM in
Wearables