lua
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
lua [2015/03/19 17:53] – [Scheduling Animations / Functions] alex_curran | lua [2020/07/24 09:32] (current) – alexcurran1 | ||
---|---|---|---|
Line 16: | Line 16: | ||
(Note: | (Note: | ||
+ | |||
===== Conditional Statements ===== | ===== Conditional Statements ===== | ||
- | Conditionals | + | Conditional statements |
+ | |||
+ | |||
+ | ===== Conditional Value Assignment ===== | ||
+ | These allow you to conditionally set a value to a property based on some conditions, the syntax uses (IF-AND-OR). | ||
It's easy once you know this: | It's easy once you know this: | ||
Line 25: | Line 30: | ||
^ IF < | ^ IF < | ||
- | Simple | + | A simple |
({dm} % 2 == 0) and ' | ({dm} % 2 == 0) and ' | ||
- | More complex example: | + | A more complex example: |
({dh} < 11) and ' | ({dh} < 11) and ' | ||
| | ||
- | Note the parentheses. | + | Note the parentheses. |
+ | |||
+ | Here's another example of why it's a good idea to add parentheses: | ||
({dh} > 23 or {dh} < 1) and ' | ({dh} > 23 or {dh} < 1) and ' | ||
Line 50: | Line 57: | ||
===== Strings ===== | ===== Strings ===== | ||
- | Texts can be manipulated through the [[http:// | + | Text [[http:// |
+ | |||
+ | You can quote strings with double or single quotes so 'some text' is also a string. | ||
==== Methods ==== | ==== Methods ==== | ||
Line 56: | Line 65: | ||
Upper/ | Upper/ | ||
- | string.upper({ddww}) | + | string.upper('{ddww}') |
- | string.lower({ddww}) | + | string.lower('{ddww}') |
Reverse a string: | Reverse a string: | ||
- | string.reverse({ddww}) | + | string.reverse('{ddww}') |
Shorten a string (use only first 20 chars): | Shorten a string (use only first 20 chars): | ||
Line 132: | Line 141: | ||
You are recommended to keep Tap Action scripts shorter e.g. by running functions in the main script file, as Tap Action scripts are stored in the XML file and not the separate script file. | You are recommended to keep Tap Action scripts shorter e.g. by running functions in the main script file, as Tap Action scripts are stored in the XML file and not the separate script file. | ||
- | ===== Run Lua Function Every Second or Millisecond ===== | + | ===== Run Lua Function Every Hour, Minute, |
+ | |||
+ | function on_hour(h) | ||
+ | function on_minute(h, | ||
+ | function on_second(h, | ||
+ | function on_millisecond(dt) | ||
If you have some custom variables that update every millisecond, | If you have some custom variables that update every millisecond, | ||
Line 177: | Line 191: | ||
to -- ending property value (numeric) | to -- ending property value (numeric) | ||
duration | duration | ||
- | easing | + | easing |
start_offset | start_offset | ||
Schedule a sleep delay of e.g. 1s, which is useful for chaining animations : | Schedule a sleep delay of e.g. 1s, which is useful for chaining animations : | ||
Line 195: | Line 209: | ||
WatchMaker extends the Lua commandset. Just use the wm_action() or other functions anywhere in your script or tap actions : | WatchMaker extends the Lua commandset. Just use the wm_action() or other functions anywhere in your script or tap actions : | ||
- | wm_action(' | + | wm_action(' |
- | wm_action(' | + | wm_action(' |
- | wm_action(' | + | wm_action(' |
- | wm_action(' | + | wm_action(' |
+ | | ||
+ | wm_action(' | ||
+ | wm_action(' | ||
+ | wm_action(' | ||
+ | wm_action(' | ||
+ | wm_action(' | ||
+ | wm_action(' | ||
+ | | ||
wm_schedule(' | wm_schedule(' | ||
wm_unschedule_all() | wm_unschedule_all() | ||
- | wm_tag(' | + | |
+ | wm_sfx(' | ||
+ | wm_transition(' | ||
+ | wm_anim_set(' | ||
+ | wm_anim_set(' | ||
+ | wm_anim_start(' | ||
+ | | ||
+ | | ||
is_bright | is_bright | ||
Line 225: | Line 253: | ||
You can write your own tweening function like this : | You can write your own tweening function like this : | ||
- | function linear_myversion(t, b, c, d) | + | function linear_myversion(d, b, c, t) |
return c * t / d + b | return c * t / d + b | ||
end | end | ||
| | ||
- | function inQuad_myversion(t, b, c, d) | + | function inQuad_myversion(d, b, c, t) |
t = t / d | t = t / d | ||
return c * math.pow(t, 2) + b | return c * math.pow(t, 2) + b | ||
end | end | ||
| | ||
- | -- t = time == how much time has to pass for the tweening to complete | + | -- t = time == running time. How much time has passed *right now* |
-- b = begin == starting property value | -- b = begin == starting property value | ||
-- c = change == ending - beginning | -- c = change == ending - beginning | ||
- | -- d = duration == running time. How much time has passed *right now* | + | -- d = duration == how much time has to pass for the tweening to complete |
+ | |||
+ | ===== Transitions ===== | ||
+ | |||
+ | From WatchMaker 3.6, you can run over 45 transitions when switching between screens on a watchface. | ||
+ | |||
+ | wm_transition(' | ||
+ | This will start a transition to the next screen. | ||
+ | |||
+ | Free Transitions Watch: http:// | ||
+ | |||
+ | See video of all transitions here: http:// | ||
+ | |||
+ | You should not use wm_transition for bright / dim animations - instead set the transition directly in WatchMaker watch editor. | ||
+ | |||
+ | The full list of transitions is shown below (you can add spaces if needed or use lower-case) : | ||
+ | None, Random, | ||
+ | FlipFromLeft, | ||
+ | ScrollFromLeft, | ||
+ | SlideFromLeft, | ||
+ | CrossHatch, CrossZoom, CubeFromLeft, | ||
+ | Dreamy, DreamyZoom, Fade, | ||
+ | FoldFromLeft, | ||
+ | GlitchDisplace, | ||
+ | SquareSwipe, | ||
+ | HSVFade, LinearBlur, RandomSquares, | ||
+ | PageCurl, Radial, PowerDisformation, | ||
+ | FadeBlack, FadeWhite, CircleOpen, | ||
+ | |||
===== Learn More ===== | ===== Learn More ===== | ||
You can learn more about how to use Lua from the many use cases listed on our [[tips: | You can learn more about how to use Lua from the many use cases listed on our [[tips: |
lua.txt · Last modified: 2020/07/24 09:32 by alexcurran1